Strange issue with Zend_Validate_Identical? - zend-form

I had write the following code in my Zend Form:
$newpassword = new Zend_Form_Element_Password('newpassword');
$newpassword->setLabel("Enter your New Password :")
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator(
'NotEmpty',
TRUE,
array('messages' => array(
'isEmpty' => 'Please enter new password.'
)
)
)
->addValidator(
'Alnum',
TRUE,
array('messages' => array(
'alnumInvalid' => 'Please enter a valid new password.',
'notAlnum' => 'Please enter a valid new password.',
'alnumStringEmpty' => 'Please enter a valid new password.'
)
)
)
->addValidator('StringLength', false, array(4, 25))
->getValidator('StringLength')->setMessage("Should be 4-25 characters long.");
$retypepassword = new Zend_Form_Element_Password('retypepassword');
$retypepassword->setLabel("Retype-Password :")
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator(
'NotEmpty',
TRUE,
array('messages' => array(
'isEmpty' => 'Please enter confirm password.'
)
)
)
->addValidator(
new Zend_Validate_Identical('newpassword'),
TRUE,
array('messages' => array(
'notSame' => 'New password and confirm password are not matching. They must be same.',
'missingToken' => 'New password and confirm password are not matching. They must be same.'
)
)
)
->addValidator('StringLength', false, array(4, 25))
->getValidator('StringLength')->setMessage("Should be 4-25 characters long.");
As you can see that I had override the error messages for Zend_Validate_Identical i.e. for notSame and missignToken, but still the form is showing the default error message i.e. "The two given tokens do not match"
Can anyone please help me.
Thanks In Advance...

The $options parameter to Zend_Form_Element::addValidator gets ignored completely if you pass it a validator object (which you're doing by passing new Zend_Validate_Identical).
Instead, you want to do something closer to the way you've added your other validators:
$this->addValidator(
'Identical',
TRUE,
array('token' => 'newpassword',
'messages' => array(
'notSame' => 'New password and confirm password are not matching. They must be same.',
'missingToken' => 'New password and confirm password are not matching. They must be same.'
)
)
);

Related

how to integrate multimodelform with echmultiselect yii?

I am running into a little snag with combining extensions "EchMultiSelect" and "MultiModelForm" of YII framework.
What I'm trying to do is copy a set of form elements one of which elements is an EchMultiSelect widget.
According to tutorial on the jqRelCopy page, I would need to pass a copy of the element (datePicker in their example) to the 'jsAfterNewId' option:
'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker($datePickerConfig),
So, I tried to modify that to:
'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
Where I also added the following to MultiModelForm.php:
public static function afterNewIdMultiSelect($element)
{
$options = isset($element['options']) ? $element['options'] : array();
$jsOptions = CJavaScript::encode($options);
return "if(this.attr('multiple')=='multiple'){this.multiselect(jQuery.extend({$jsOptions}));};";
}
its copied and working properly when i am using Add Person link but what happens if i am adding/cloning three items for example and when i change the third item multiselct option then its reflecting to the first multiselect dropdown only this is same for other as well also when i am adding new items by clicking on the Add Person link then its cloning the same element to the new row item
here is the code for the form configuration variables and multimodel widget call.
//$userList=array of the userIds from users table
$memberFormConfig = array(
'elements'=>array(
'userId'=>array(
'type'=>'ext.EchMultiSelect.EchMultiSelect',
'model' => $User,
'dropDownAttribute' => 'userId',
'data' => $userList,
'dropDownHtmlOptions'=> array(
'style'=>'width:500px;',
),
),
...
...
));
calling the MultiModelForm widget from the same view file
$this->widget('ext.multimodelform.MultiModelForm',array(
'id' => 'id_member', //the unique widget id
'formConfig' => $memberFormConfig, //the form configuration array
'model' => $model, //instance of the form model
'tableView' => true,
'validatedItems' => $validatedMembers,
'data' => Person::model()->findAll('userId=:userId', array(':userId'=>$model->id)),
'addItemText' => 'Add Person',
'showAddItemOnError' => false, //not allow add items when in validation error mode (default = true)
'fieldsetWrapper' => array('tag' => 'div',
'htmlOptions' => array('class' => 'view','style'=>'position:relative;background:#EFEFEF;')
),
'removeLinkWrapper' => array('tag' => 'div',
'htmlOptions' => array('style'=>'position:absolute; top:1em; right:1em;')
),
'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
));
Can someone help me with this please?
Thanks in advance!
After a long searching and googleing i found the solution for this, just replace the function in your MultiModelForm.php:
public static function afterNewIdMultiSelect($element)
{
$options = isset($element['options']) ? $element['options'] : array();
$jsOptions = CJavaScript::encode($options);
return "if ( this.hasClass('test123456') )
{
var mmfComboBoxParent = this.parent();
// cloning autocomplete and select elements (without data and events)
var mmfComboBoxClone = this.clone();
var mmfComboSelectClone = this.prev().clone();
// removing old combobox
mmfComboBoxParent.empty();
// addind new cloden elements ()
mmfComboBoxParent.append(mmfComboSelectClone);
mmfComboBoxParent.append(mmfComboBoxClone);
// re-init autocomplete with default options
mmfComboBoxClone.multiselect(jQuery.extend({$jsOptions}));
}";
}
Thats It....!!
Thanks...!!!

Drupal module's list of permissions are stuck

From what I understand, my problem is that I am (rather, my client is) running an older version of Drupal, specifically Core 6.26 If you're curious about any additional specs, I'll be happy to divulge.
With that out of the way, I made a new module with the following menu hook.
function checkin_menu(){
$items = array();
$items['checkin'] = array(
'title' => 'Checkin'
,'type' => MENU_CALLBACK
,'access arguments' => array('checkin')
,'page callback' => 'checkin'
);
}
The permissions listed out exactly what I expected. There was a section called "Checkin" the same as the module's name as specified in the .info file, and one item to give permissions to "checkin"
Later on I expanded the module to have two different paths. The second one is supposed to be for admins only.
function checkin_menu(){
$items = array();
$items['checkin'] = array(
'title' => 'Checkin'
,'type' => MENU_CALLBACK
,'access arguments' => array('create a checkin')
,'page callback' => 'checkin'
);
$items['checkin_admin'] = array(
'title' => 'Checkin Admin'
,'type' => MENU_CALLBACK
,'access arguments' => array('view all checkins')
,'page callback' => 'device_checkin_page'
);
return $items;
}
Much to my surprise neither "create a checkin" or "view all checkins" is showing up. I still have the original "checkins" showing on the permissions page. I've been hunting for answers for a couple days now. Help a guy out?
Permissions are defined by a different hook, which is hook_perm.
So you should be doing something like this:
/**
* Implementation of the hook_perm()
*/
function checkin_perm() {
return array (
'create a checkin',
'view all checkins',
);
}

Insert statement not working using execute(array()) of PDO Extension

$stmt = $conn->prepare("INSERT INTO user VALUES ('',:username,md5(:password),'',1,'','',:email,'',0,0,'',:cover,:dateofbirthYear:dateofbirthMonth:dateofbirthDay,NOW(),:sex,:country)");
$stmt->execute(array(
':username' => $username,
':password' => $password,
':email' => $email,
':cover' => $cover,
':dateofbirthYear' => $dateofbirthYear,
':dateofbirthMonth' => $dateofbirthMonth,
':dateofbirthDay' => $dateofbirthDay,
':sex' => $sex,
':country' => $country
));
For some reason this insert statement is not working. I am very new in PDO so I do not know much about it. What am I doing wrong?
this statment gives me this error :
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in /home/manga/public_html/new/register.php:80 Stack trace:
#0 /home/manga/public_html/new/register.php(80): PDOStatement->execute(Array)
#1 {main} thrown in /home/manga/public_html/new/register.php on line 80
You have prepared your query in the wrong way
INSERT INTO user VALUES ('',:username,md5(:password),'',1,'','',:email,'',0,0,'',
:cover,:dateofbirthYear:dateofbirthMonth:dateofbirthDay,NOW(),:sex,:country
// ^ These need to either single or separated
For what you are trying, you can do it this way
//Prepare the date of birth earlier
$dob = $dateofbirthYear.$dateofbirthMonth.$dateofbirthDay;
//Then pass it as a single $variable
$stmt = $conn->prepare("INSERT INTO user VALUES ('',:username,md5(:password),'',1,'','',:email,'',0,0,'',:cover,:dob,NOW(),:sex,:country)");
$stmt->execute(array(
':username' => $username,
':password' => $password,
':email' => $email,
':cover' => $cover,
':dob' => $dob, // <-- Problem solved
':sex' => $sex,
':country' => $country
));
// Then it will execute
The exact error message you have is:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
This means that the number/names of parameters you have passed (the array() in execute) does not match with the number/names of parameters you have in the prepare() SQL-query.
If you compare that with the other questions that contain SQLSTATE[HY093] you will see that it is often related to code that is large and bad formatted which is hard to read. That makes it hard to count. And then you have an oversight of something and then the error happened.
Just fix it and done, for example you can not make one parameter out of three names:
,:dateofbirthYear:dateofbirthMonth:dateofbirthDay,
Instead just pass one parameter for the birthday:
, :dateofbirth,
You can also make your code a bit more readable:
$stmt = $conn->prepare(
"INSERT INTO user
VALUES (
'', :username, md5(:password), '', 1, '', '', :email, '', 0, 0, '',
:cover, :dateofbirth, NOW(), :sex, :country
)"
);
$stmt->execute(array(
':username' => $username,
':password' => $password,
':email' => $email,
':cover' => $cover,
':dateofbirth' => $dateofbirthYear . $dateofbirthMonth . $dateofbirthDay,
':sex' => $sex,
':country' => $country
));
And then you have a security problem with the password hash:
md5(:password)
Instead do proper password hashing, see the PHP FAQ about Safe Password Hashing.
Corrected prepared query:
$stmt = $conn->prepare("INSERT INTO user VALUES ('',:username,md5(:password),'',1,'','',:email,'',0,0,'',:cover,:dateofbirthYear,:dateofbirthMonth:,dateofbirthDay,NOW(),:sex,:country)");
//:dateofbirthYear,:dateofbirthMonth:,dateofbirthDay place holders are seprated
$stmt->execute(array(
':username' => $username,
':password' => $password,
':email' => $email,
':cover' => $cover,
':dateofbirthYear' => $dateofbirthYear,
':dateofbirthMonth' => $dateofbirthMonth,
':dateofbirthDay' => $dateofbirthDay,
':sex' => $sex,
':country' => $country
));

zend framework 2 autentification using DbTable failure

I have followed the zend instructions for implement my web Authentication using a database table.
It's exactly the same code, but when render the page, the following exceptions appears:
Zend\Authentication\Adapter\Exception\RuntimeException
File:
C:\xampp\htdocs\pfc\vendor\ZF2\library\Zend\Authentication\Adapter\DbTable.php
Mensaje:
The supplied parameters to DbTable failed to produce a valid sql statement, please
check table and column names for validity.
produced by this other:
Zend\Db\Adapter\Exception\InvalidQueryException
File:
C:\xampp\htdocs\pfc\vendor\ZF2\library\Zend\Db\Adapter\Driver\Mysqli\Statement.php
Mensaje:
Statement couldn't be produced with sql: SELECT `users`.*, (CASE WHEN `password` = ?
THEN 1 ELSE 0 END) AS `zend_auth_credential_match` FROM `users` WHERE `mail` = ?
Seems to be that Statement.php can not execute the sql of above, but I send the sql by phpmyadmin replacing the ? for strings and work ok.
I am sure that $dbAdapter works ok also because I have tested it and the columns name are
"mail" and "password".
This in my code, also I put the $dbAdapter test code.
$dbAdapter = new DbAdapter(array( //This DbAdapter Work ok sure!!
'driver' => 'Mysqli',
'database' => 'securedraw',
'username' => 'root',
'password' => ''
));
$fp = function($name) use ($dbAdapter) { return $dbAdapter->driver->formatParameterName($name);};
$sql = 'SELECT * FROM ' . $qi('users') . ' WHERE id = ' . $fp('id');
$statement = $dbAdapter->query($sql);
$parameters = array('id' => 1);
$sqlResult = $statement->execute($parameters);
$row = $sqlResult->current();
$mail = $row['mail'];
$password = $row['password']; //until here test $dbAdapter exitly!!
//Start the auth proccess!!
$authAdapter = new AuthDbTableAdapter($dbAdapter);
$authAdapter->setTableName('users')
->setIdentityColumn('mail')
->setCredentialColumn('password');
$authAdapter->setIdentity('josep')
->setCredential('josep');
$authResult = $authAdapter->authenticate(); //This is the fail method!!!
After more research on the subject, I discovered that if changed the driver of the dbAdapter to pdo_mysql, authenticate method works ok.
The problem is I don't want use PDO because the SGBD won't change in the future.
Somebody know because happen this?
This may seems old but I was able to solve this error. This error is caused from you MySQL version.
This one works for me. All you need to do is to remove the driver_options from your db setup, this code is usually located at your global.php or .local.php from your Config file.
Change FROM:
'db' => array(
'driver' => 'Pdo_Mysql',
'dsn' => 'mysql:dbname=dbName;host=localhost',
'username' => 'dbUser',
'password' => 'dbPass',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
TO
'db' => array(
'driver' => 'Pdo_Mysql',
'dsn' => 'mysql:dbname=dbName;host=localhost',
'username' => 'dbUser',
'password' => 'dbPass',
),
Thank you. This solution solved my problem.

yii tokeninput extension cursor focus on wrong place after same match?

I am having problem with yii tokeninput extension. When i search name it gives the user list and if i select any name and if that name is also selected previous than the cursor point after the selected item, it does not point at the end of all the the item in the input box.
I am using this configuration.
$this->widget('ext.tokeninput.TokenInput', array(
'model' => $model,
'attribute' => 'USER_ID',
'url'=>$this->createUrl('user/searchUserNames'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
// 'resultsFormatter' => 'js:function(item){ return “<li><p>” + item.name + “</p></li>” }',
'theme' => 'facebook',
//'hintText' => 'Type',
'prePopulate' => $prePopulate,
'processPrePopulate' => $processPrePopulate,
)
));
I have also lookout at the examples but does not find the solution. can any one help me ?
Loopj: jquery token input demo
plz comment the line number 509 in **jquery.tokeninput.js**
input_token.insertAfter(found_existing_token);
that line insert cursor after that selected item so if you comment
this line cursor is at the end of all names