public function init() { $this->setMethod('post'); //The password element. $passwordElement = new Zend_Form_Element_Password('password'); $passwordElement->setRequired(true); $passwordElement->setLabel('New Password:'******'confirm_password'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement->addValidator($validator); $this->addElement($passwordElement); //The confirm password element. $confirmPasswordElement = new Zend_Form_Element_Password('confirm_password'); $confirmPasswordElement->setRequired(true); $confirmPasswordElement->setLabel('Confirm New Password:'******'Please confirm your password'); $confirmPasswordElement->addValidator($validator); $this->addElement($confirmPasswordElement); // Security question & answer $this->addElement('select', 'security_question', array('label' => 'Security Question', 'required' => true, 'multiOptions' => array(0 => 'Please select'), 'decorators' => array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))))); $this->addElement('text', 'security_answer', array('label' => 'Answer', 'required' => true, 'filters' => array('StringTrim'), 'attribs' => array('data-ctfilter' => 'yes'))); $this->addElement('hidden', 'instruction', array('required' => false)); $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Save', 'class' => 'button')); $this->setElementDecorators(array('ViewHelper', 'Label', 'Errors', array('HtmlTag', array('tag' => 'div')))); // Set up the decorator on the form and add in decorators which are removed $this->addDecorator('FormElements')->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'form_section one-col'))->addDecorator('Form'); $element = $this->getElement('submit'); $element->removeDecorator('label'); // Remove the label from the submit button }
public function init() { $this->setAttrib('class', 'form-horizontal'); $login = new Zend_Form_Element_Text('login'); $login->setRequired()->addValidator('StringLength', false, array('max' => 32))->setLabel('Nom d\'utilisateur'); $db = Zend_Db_Table::getDefaultAdapter(); $validator = new Zend_Validate_Db_NoRecordExists(array('adapter' => $db, 'schema' => 'twitter', 'table' => 'membre', 'field' => 'login')); $validator->setMessage("Le login '%value%' est déjà utilisé"); $login->addValidator($validator); $pass = new Zend_Form_Element_Password('pass'); $pass->setLabel('Mot de passe')->setRequired(); $passConfirm = new Zend_Form_Element_Password('confirm'); $passConfirm->setLabel('Confirmer le mot de passe'); $validator = new Zend_Validate_Identical('pass'); $validator->setMessage('La confirmation ne correspond pas au mot de passe'); $passConfirm->addValidator($validator); //$passConfirm->addValidator('Identical', false, array('token')); $hash = new Zend_Form_Element_Hash('hash'); $submit = new Zend_Form_Element_Submit('Inscription'); $cancel = new Zend_Form_Element_Button('Annuler'); $this->addElements(array($login, $pass, $passConfirm, $hash, $submit, $cancel)); // add display group $this->addDisplayGroup(array('login', 'pass', 'confirm', 'Inscription', 'Annuler'), 'users'); $this->getDisplayGroup('users')->setLegend('S\'inscrire'); // set decorators EasyBib_Form_Decorator::setFormDecorator($this, EasyBib_Form_Decorator::BOOTSTRAP, 'Inscription', 'Annuler'); }
private function _setupElements() { $translate = Zend_Registry::get('Zend_Translate'); $this->setAttrib('id', 'signupForm'); $this->setTranslator($translate); $email = new Zend_Form_Element_Text('email'); $email->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->addValidator('NotEmpty')->removeDecorator('HtmlTag')->removeDecorator('DtDWrapper')->removeDecorator('label')->setAttrib('id', 'email')->addValidator('EmailAddress'); $email->addValidator(new Ziown_Form_Validate_EmailAddress(), false); $email->getValidator('NotEmpty')->setMessage('Email Address is Required', 'isEmpty'); $username = new Zend_Form_Element_Text('username'); $username->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->addValidator('NotEmpty')->removeDecorator('HtmlTag')->removeDecorator('DtDWrapper')->removeDecorator('label')->setAttrib('id', 'username'); $username->addValidator(new Ziown_Form_Validate_UserName()); $username->getValidator('NotEmpty')->setMessage('User name is Required', 'isEmpty'); $password = new Zend_Form_Element_Password('password'); $password->setRequired(true)->removeDecorator('HtmlTag')->removeDecorator('DtDWrapper')->removeDecorator('label')->setAttrib('id', 'txt-password')->setErrorMessages(array('Password is required')); $identValidator = new Zend_Validate_Identical($_POST['password']); $identValidator->setMessages(array('notSame' => 'Password doesn\'t match!', 'missingToken' => 'Password doesn\'t match!')); $confirm_password = new Zend_Form_Element_Password('confirm_password'); $confirm_password->setRequired(true)->removeDecorator('HtmlTag')->removeDecorator('DtDWrapper')->removeDecorator('label')->setAttrib('id', 'txt-confirm-password')->addValidator($identValidator); $signup = new Zend_Form_Element_Submit('signup'); $signup->setLabel('Sign Up'); $signup->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setAttrib('class', 'u-login'); $this->setDecorators(array(array('ViewScript', array('script' => 'signup.phtml')))); $this->addElements(array($username, $password, $confirm_password, $signup, $email)); }
/** * Adds validation rule for user password confirmation * * @param \Magento\Framework\Validator\DataObject $validator * @param string $passwordConfirmation * @return \Magento\Framework\Validator\DataObject */ public function addPasswordConfirmationRule(\Magento\Framework\Validator\DataObject $validator, $passwordConfirmation) { $passwordConfirmation = new \Zend_Validate_Identical($passwordConfirmation); $passwordConfirmation->setMessage(__('Your password confirmation must match your password.'), \Zend_Validate_Identical::NOT_SAME); $validator->addRule($passwordConfirmation, 'password'); return $validator; }
public static function overridePasswordIdenticalValidator($p_matchAgainst) { $validator = new Zend_Validate_Identical(); $validator->setToken($p_matchAgainst); $validator->setMessage(_("Passwords do not match"), Zend_Validate_Identical::NOT_SAME); return $validator; }
/** * Create user details form (single user). * * @return void */ public function init() { // Invoke the agent user manager $agentUserManager = new Manager_Core_Agent_User(); // Create array of possible security questions $securityQuestions = array('' => '--- please select ---'); $securityQuestions += $agentUserManager->getUserSecurityAllQuestions(); // Add real name element $this->addElement('text', 'realname', array('label' => 'Full name', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your full name', 'notEmptyInvalid' => 'Please enter your full name'))), array('regex', true, array('pattern' => '/^[a-z\\-\\ \']{2,}$/i', 'messages' => 'Name must contain at least two alphabetic characters and only basic punctuation (hyphen, space and single quote)'))))); // Add username element $this->addElement('text', 'username', array('label' => 'Username', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your username', 'notEmptyInvalid' => 'Please enter your username'))), array('regex', true, array('pattern' => '/^[a-z0-9]{1,64}$/i', 'messages' => 'Username must contain between 1 and 64 alphanumeric characters'))))); if ($this->_role == Model_Core_Agent_UserRole::MASTER) { $this->getElement('username')->setRequired(true); } else { $this->getElement('username')->setAttrib('disabled', 'disabled'); } // Add password1 element $passwordElement1 = new Zend_Form_Element_Password('password1'); $passwordElement1->setRequired(false); $passwordElement1->setLabel('New password:'******'password2'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement1->addValidator($validator); $passwordElement2 = new Zend_Form_Element_Password('password2'); $passwordElement2->setRequired(false); $passwordElement2->setLabel('New password (again)'); $this->addElement($passwordElement2); // Add e-mail element $this->addElement('text', 'email', array('label' => 'E-mail address', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your e-mail address')))))); $emailValidator = new Zend_Validate_EmailAddress(); $emailValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Domain name invalid in e-mail address', Zend_Validate_EmailAddress::INVALID_FORMAT => 'Invalid e-mail address')); $this->getElement('email')->addValidator($emailValidator); if ($this->_role == Model_Core_Agent_UserRole::MASTER) { $this->getElement('email')->setRequired(true); } else { $this->getElement('email')->setAttrib('disabled', 'disabled'); } // Add e-mail element $this->addElement('text', 'emailcopyto', array('label' => 'Copy e-mail to', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter a copy-to e-mail address')))))); $emailCopyToValidator = new Zend_Validate_EmailAddress(); $emailCopyToValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Domain name invalid in copy-to e-mail address', Zend_Validate_EmailAddress::INVALID_FORMAT => 'Invalid copy-to e-mail address')); $this->getElement('emailcopyto')->addValidator($emailCopyToValidator); // Add security question element $this->addElement('select', 'question', array('label' => 'Security question', 'required' => false, 'multiOptions' => $securityQuestions)); // Add security answer element $this->addElement('text', 'answer', array('label' => 'Security answer', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('regex', true, array('pattern' => '/^[\\w\\ \\.\\-\'\\,]{2,}$/i', 'messages' => 'Security answer must contain at least two characters and only basic punctuation (hyphen, apostrophe, comma, full stop and space)'))))); // Add master user element $this->addElement('checkbox', 'master', array('label' => 'Master user', 'required' => false, 'checkedValue' => '1', 'uncheckedValue' => '0')); // Add agent reports element $this->addElement('checkbox', 'reports', array('label' => 'Agent reports', 'required' => false, 'checkedValue' => '1', 'uncheckedValue' => '0')); // Add status element $this->addElement('checkbox', 'status', array('label' => 'Active', 'required' => false, 'checkedValue' => '1', 'uncheckedValue' => '0')); // Set custom subform decorator $this->setDecorators(array(array('ViewScript', array('viewScript' => 'settings/subforms/useraccount.phtml', 'role' => $this->_role)))); $this->setElementFilters(array('StripTags')); $this->setElementDecorators(array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false)))); }
public function isValid($data) { // validate that the value given for the 'newPasswordConfirm' field is identical to the 'newPassword' field $validator = new Zend_Validate_Identical($data['newPassword']); $validator->setMessages(array(Zend_Validate_Identical::NOT_SAME => 'Passwords do not match', Zend_Validate_Identical::MISSING_TOKEN => 'Passwords do not match')); $this->getElement('newPasswordConfirm')->addValidator($validator); return parent::isValid($data); }
public function isValid($data) { $passwordConfirmation = $this->getElement('passwordConfirmation'); if (!empty($data['MP_Password'])) { $passwordConfirmation->setRequired(true)->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('error_message_password_isEmpty')))); $Identical = new Zend_Validate_Identical($data['MP_Password']); $Identical->setMessages(array('notSame' => $this->getView()->getCibleText('error_message_password_notSame'))); $passwordConfirmation->addValidator($Identical); } return parent::isValid($data); }
/** * Initializes the form element. */ function init() { parent::init(); // set label $this->setLabel('Confirm password'); // add validataor for comparison with NewPassword element $newPassword = Zend_Controller_Front::getInstance()->getRequest()->getParam('new_password'); $validator = new Zend_Validate_Identical($newPassword); $validator->setMessage("The passwords do not match."); $this->addValidator($validator); }
public function init() { // Set request method $this->setMethod('post'); // Email entry $this->addElement('span', 'email', array('label' => 'Email address', 'required' => false, 'filters' => array('StringTrim'), 'class' => 'formvalue', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your email address')))))); // Modify email error messages & add validator $emailValidator = new Zend_Validate_EmailAddress(); $emailValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => "Domain name invalid in email address", Zend_Validate_EmailAddress::INVALID_FORMAT => "Invalid email address")); $this->getElement('email')->addValidator($emailValidator); //The password element. $passwordElement = new Zend_Form_Element_Password('password'); $passwordElement->setRequired(true); $passwordElement->setLabel('Create your password'); $passwordElement->setOptions(array('data-noAjaxValidate' => '1')); $passwordElement->addValidator(new Zend_Validate_PasswordStrength()); $validator = new Zend_Validate_Identical(); $validator->setToken('confirm_password'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement->addValidator($validator); $this->addElement($passwordElement); //The confirm password element. $confirmPasswordElement = new Zend_Form_Element_Password('confirm_password'); $confirmPasswordElement->setRequired(true); $confirmPasswordElement->setLabel('Re-enter password'); $confirmPasswordElement->setOptions(array('data-noAjaxValidate' => '1')); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please confirm your password'); $confirmPasswordElement->addValidator($validator); $this->addElement($confirmPasswordElement); // Security question & answer $securityQuestionModel = new Datasource_Core_SecurityQuestion(); $securityQuestionOptions = array(0 => '- Please Select -'); foreach ($securityQuestionModel->getOptions() as $option) { $securityQuestionOptions[$option['id']] = $option['question']; } $this->addElement('select', 'security_question', array('label' => 'Security Question', 'required' => false, 'multiOptions' => $securityQuestionOptions, 'decorators' => array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))))); /* Value no longer mandatory, Redmine #11873 $questionElement = $this->getElement('security_question'); $validator = new Zend_Validate_GreaterThan(array('min'=> 0)); $validator->setMessage('You must select a security question'); $questionElement->addValidator($validator); */ $this->addElement('text', 'security_answer', array('label' => 'Answer', 'required' => false, 'filters' => array('StringTrim'))); // Set custom subform decorator - this is the default and gets overridden by view scripts in the tenants' and landlords' Q&Bs $this->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/register.phtml')))); // Set element decorators $this->setElementDecorators(array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false)))); // Grab view and add the client-side password validation JavaScript into the page head $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $view->headScript()->appendFile('/assets/common/js/passwordValidation.js', 'text/javascript'); }
protected function setUp() { $this->_model = new \Magento\Framework\Validator\Object(); $fieldOneExactValue = new \Zend_Validate_Identical('field_one_value'); $fieldOneExactValue->setMessage("'field_one' does not match expected value"); $fieldOneLength = new \Zend_Validate_StringLength(['min' => 10]); $fieldTwoExactValue = new \Zend_Validate_Identical('field_two_value'); $fieldTwoExactValue->setMessage("'field_two' does not match expected value"); $fieldTwoLength = new \Zend_Validate_StringLength(['min' => 5]); $entityValidity = new \Zend_Validate_Callback([$this, 'isEntityValid']); $entityValidity->setMessage('Entity is not valid.'); $this->_model->addRule($fieldOneLength, 'field_one')->addRule($fieldOneExactValue, 'field_one')->addRule($fieldTwoLength, 'field_two')->addRule($fieldTwoExactValue, 'field_two')->addRule($entityValidity); }
/** * Initialise the form * * @todo Validation * @return void */ public function init() { // Set request method $this->setMethod('POST'); // Add title element $this->addElement('select', 'title', array('label' => 'Title', 'required' => true, 'multiOptions' => TenantsInsuranceQuote_Form_Subforms_PersonalDetails::$titles, 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select your title', 'notEmptyInvalid' => 'Please select your title')))), 'class' => 'form-control')); // Add first name element $this->addElement('text', 'first_name', array('label' => 'First name', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your first name', 'notEmptyInvalid' => 'Please enter your first name'))), array('regex', true, array('pattern' => '/^[a-z\\-\\ \']{2,}$/i', 'messages' => 'First name must contain at least two alphabetic characters and only basic punctuation (hyphen, space and single quote)'))), 'class' => 'form-control')); // Add last name element $this->addElement('text', 'last_name', array('label' => 'Last name', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your last name'))), array('regex', true, array('pattern' => '/^[a-z\\-\\ \']{2,}$/i', 'messages' => 'Last name must contain at least two alphabetic characters and only basic punctuation (hyphen, space and single quote)'))), 'class' => 'form-control')); // Email element $this->addElement('text', 'email', array('label' => 'Email Address', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Email address is required')))), 'class' => 'form-control')); // Modify email error messages & add validator $emailValidator = new Zend_Validate_EmailAddress(); $emailValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => "Domain name invalid in email address", Zend_Validate_EmailAddress::INVALID_FORMAT => "Invalid email address")); $this->getElement('email')->addValidator($emailValidator); //The password element. $passwordElement = new Zend_Form_Element_Password('password', array('validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Password is required')))), 'class' => 'form-control')); $passwordElement->setRequired(true); $passwordElement->setLabel('Password'); $passwordElement->setAttribs(array('class' => 'form-control')); $passwordElement->addValidator(new Zend_Validate_PasswordStrength()); $validator = new Zend_Validate_Identical(); $validator->setToken('confirm_password'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement->addValidator($validator); $this->addElement($passwordElement); //The confirm password element. $confirmPasswordElement = new Zend_Form_Element_Password('confirm_password'); $confirmPasswordElement->setRequired(true); $confirmPasswordElement->setLabel('Confirm Password'); $confirmPasswordElement->setAttribs(array('class' => 'form-control')); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please confirm your password'); $confirmPasswordElement->addValidator($validator); $this->addElement($confirmPasswordElement); // Security question & answer $this->addElement('select', 'security_question', array('label' => 'Security Question', 'required' => true, 'multiOptions' => array('' => 'Please select'), 'decorators' => array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Security question is required')))), 'class' => 'form-control')); $this->addElement('text', 'security_answer', array('label' => 'Answer', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Security answer is required')))), 'class' => 'form-control')); $this->addElement('hidden', 'refno', array('required' => false, 'class' => 'noalt')); // Add the submit button $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Register', 'class' => 'btn btn-primary pull-right')); // Set up the element decorators $this->setElementDecorators(array('ViewHelper', 'Label', 'Errors')); // Set up the decorator on the form and add in decorators which are removed $this->addDecorator('FormElements')->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'form_section'))->addDecorator('Form'); // Remove the label from the submit button $element = $this->getElement('submit'); $element->removeDecorator('label'); $this->getElement('refno')->removeDecorator('HtmlTag'); }
/** * Profile form. * * @param User $user * @return Curry_Form */ private function getForm(User $user) { $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('name' => array('text', array('label' => 'Username', 'required' => true, 'value' => $user->getName())), 'old_password' => array('password', array('label' => 'Password', 'description' => 'You can leave this blank if you dont wish to change password.')), 'password' => array('password', array('label' => 'New password')), 'password_confirm' => array('password', array('label' => 'Confirm password')), 'save' => array('submit', array('label' => 'Save'))))); if (isPost() && ($_POST['old_password'] || $_POST['password'] || $_POST['password_confirm'])) { $form->old_password->setRequired(true); $form->password->setRequired(true); $form->password_confirm->setRequired(true); $form->old_password->addValidator(new Curry_Validate_Password($user)); $identical = new Zend_Validate_Identical($_POST['password']); $identical->setMessage('Passwords do not match.'); $form->password_confirm->addValidator($identical); } return $form; }
/** * Initialise the form * * @todo Validation * @return void */ public function init() { // Set request method $this->setMethod('POST'); // Add title element $this->addElement('text', 'title', array('label' => 'Title')); // Add first name element $this->addElement('text', 'first_name', array('label' => 'First name')); // Add last name element $this->addElement('text', 'last_name', array('label' => 'Last name')); $this->addElement('password', 'existing_password', array('required' => true, 'filters' => array('StringTrim'), 'class' => 'form-control')); // Email element $this->addElement('text', 'email', array('label' => 'Email Address')); //The password element. $passwordElement = new Zend_Form_Element_Password('password'); $passwordElement->setRequired(false); // New password is not required to update options $passwordElement->addValidator(new Zend_Validate_PasswordStrength()); $passwordElement->setAttribs(array('class' => 'form-control')); $validator = new Zend_Validate_Identical(); $validator->setToken('confirm_password'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement->addValidator($validator); $this->addElement($passwordElement); //The confirm password element. $confirmPasswordElement = new Zend_Form_Element_Password('confirm_password'); $confirmPasswordElement->setRequired(false); // New password is not required to update options $confirmPasswordElement->setAttribs(array('class' => 'form-control')); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please confirm your password'); $confirmPasswordElement->addValidator($validator); $this->addElement($confirmPasswordElement); // Security question & answer $this->addElement('select', 'security_question', array('required' => true, 'multiOptions' => array(0 => 'Please select'), 'decorators' => array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))), 'class' => 'form-control')); $this->addElement('text', 'security_answer', array('required' => true, 'filters' => array('StringTrim'), 'class' => 'form-control')); // Add the submit button $this->addElement('submit', 'submit', array('ignore' => true, 'class' => 'btn btn-primary pull-right', 'label' => 'Save')); // Set up the element decorators $this->setElementDecorators(array('ViewHelper', 'Label', 'Errors', array('HtmlTag', array('tag' => 'div')))); // Set up the decorator on the form and add in decorators which are removed $this->addDecorator('FormElements')->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'form_section one-col'))->addDecorator('Form'); // Set custom subform decorator $this->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/edit-account.phtml')))); // Remove the label from the submit button $element = $this->getElement('submit'); $element->removeDecorator('label'); }
/** * Initializes the form element */ function init() { // get session $session = new Zend_Session_Namespace('csrf'); // this element is required $this->setRequired(true); // this element will be ignored when getting the values from the form $this->setIgnore(true); // set the value to the stored hash $this->setValue($session->hash); // create the corresponding validator $validator = new Zend_Validate_Identical($session->hash); $validator->setMessage('The CSRF token is not valid. Please refresh the page.'); $this->addValidator($validator); // set decorators $this->setDecorators(array('ViewHelper', 'Errors')); $this->getDecorator('Errors')->setOptions(array('class' => 'daiquiri-form-error unstyled text-error')); }
public function isValid($value) { $validation = !parent::isValid($value); if ($validation) { return true; } else { $this->_error(self::Are_Equal); return false; } }
public function init() { $formErrors = $this->getView()->getHelper('FormErrors'); $formErrors->setElementStart("<div%s>")->setElementEnd("</div>")->setElementSeparator("<br>"); $validator = new Syj_Validate_EmailAddress(); $email = array('Text', 'account_email', array('label' => __("email"), 'validators' => array($validator), 'maxlength' => '320', 'required' => true)); $passValidator = new Zend_Validate_StringLength(6); $passValidator->setMessage(vsprintf($this->getTranslator()->translate("At least %d characters"), 6)); $pass = array('Password', 'account_password', array('label' => __("password"), 'required' => true, 'validators' => array($passValidator))); $identicalValidator = new Zend_Validate_Identical('account_password'); $identicalValidator->setMessage(__("Password do not match")); $pass_confirm = array('Password', 'account_password_confirm', array('label' => __("confirm password"), 'validators' => array($identicalValidator), 'allowEmpty' => false)); $pass_current = array('Password', 'account_password_current', array('label' => __("current password"))); $submit = array('Submit', 'account_submit', array('label' => __("modify my informations"))); $this->addElements(array($email, $pass, $pass_confirm, $pass_current, $submit)); $this->account_submit->setDecorators(array('ViewHelper')); // fieldset around form $this->addDisplayGroup(array_keys($this->_elements), 'main', array('decorators' => array('FormElements', array('fieldset')))); }
public function init() { $this->name = new Zend_Form_Element_Text('name'); $this->new_password = new Zend_Form_Element_Password('new_password'); $this->confirm_password = new Zend_Form_Element_Password('confirm_password'); $this->email = new Zend_Form_Element_Text('email'); $this->biography = new Zend_Form_Element_Textarea('biography'); $this->submit = new Zend_Form_Element_Submit('submit'); $email_validator = new Zend_Validate_EmailAddress(); $email_validator->setDeepMxCheck(false); $email_validator->setDomainCheck(false); $email_validator->setMessages(array(Zend_Validate_EmailAddress::INVALID_FORMAT => "Format Email Salah")); $confirm_password_validator = new Zend_Validate_Identical(); $confirm_password_validator->setMessage("Kata sandi tidak cocok."); $this->biography->setAttribs(array('style' => 'width:100%;height:240px')); $this->name->setAttribs(array('class' => 'span6', 'placeholder' => 'Nama lengkap anda')); $this->email->addValidator($email_validator)->setAttribs(array('class' => 'span4', 'placeholder' => '*****@*****.**')); $this->submit->setAttribs(array('class' => 'btn btn-success'))->setLabel('Simpan'); $this->confirm_password->addValidator($confirm_password_validator); $this->addElements(array($this->name, $this->new_password, $this->confirm_password, $this->email, $this->biography, $this->submit)); $this->setElementDecorators(array('ViewHelper', 'Errors')); }
public function init() { $this->setAction($this->_actionUrl)->setMethod('post')->setAttrib('class', 'form')->setAttrib('id', 'change-password'); $this->clearDecorators(); $fieldDecorators = array(array('ViewHelper'), array('Errors'), array('HtmlTag', array('tag' => 'li'))); $buttonDecorators = array(array('ViewHelper'), array('HtmlTag', array('tag' => 'li', 'class' => 'submit'))); $defaultDecorators = array(array('ViewHelper'), array('HtmlTag', array('tag' => 'li', 'class' => ''))); $currentPasswordValidator = new Zend_Validate_Db_RecordExists(array('table' => 'sys_user_roles', 'field' => 'password', 'adapter' => Zend_Registry::get('db'), 'exclude' => "id = " . $this->userRoleId)); $newPasswordValidator = new Zend_Validate_Db_NoRecordExists(array('table' => 'sys_user_roles', 'field' => 'password', 'adapter' => Zend_Registry::get('db'), 'exclude' => "id = " . $this->userRoleId)); $identicalValidator = new Zend_Validate_Identical(); $identicalValidator->setStrict(false)->setToken('password'); $passwordLengthValidator = new Zend_Validate_StringLength(array('min' => 1, 'max' => 10)); //current password $changePasswordNote = new Zend_Form_Element_Note('changepass_info'); $changePasswordNote->setValue('<h3>Current password</h3>')->setDecorators($defaultDecorators); $this->addElement($changePasswordNote); //current password field $this->addElement('password', 'current_password'); $this->getElement('current_password')->setRequired(true)->addFilter('StringTrim')->addValidator($currentPasswordValidator)->setDecorators($fieldDecorators); //password $passwordNote = new Zend_Form_Element_Note('password_label'); $passwordNote->setValue('<h3>New Password</h3>')->setDecorators($defaultDecorators); $this->addElement($passwordNote); //password field $this->addElement('password', 'password'); $this->getElement('password')->setRequired(true)->addFilter('StringTrim')->addValidator($passwordLengthValidator)->addValidator($newPasswordValidator)->setDecorators($fieldDecorators); //duplicate password $duplicatePasswordNote = new Zend_Form_Element_Note('repassword_label'); $duplicatePasswordNote->setValue('<h3>Type new password again</h3>')->setDecorators($defaultDecorators); $this->addElement($duplicatePasswordNote); //duplicate password field $this->addElement('password', 'repassword'); $this->getElement('repassword')->setRequired(true)->addFilter('StringTrim')->addValidator($passwordLengthValidator)->addValidator('identical', false, array('token' => 'password'))->setDecorators($fieldDecorators); //login button $this->addElement('submit', 'save'); $this->getElement('save')->setLabel('Save')->setDecorators($buttonDecorators); $this->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'ul')), array(array('DivTag' => 'HtmlTag'), array('tag' => 'div', 'class' => 'loginDiv')), 'Form')); }
/** * Fungsi inisialisasi form */ public function init() { parent::init(); // Form Attribute $this->setMethod('post'); $this->addAttribs(array('id' => 'changePasswordForm', 'action' => $this->_baseUrlHelper->baseUrl() . '/registration/change-password')); $this->setAttrib('accept-charset', 'utf-8'); // Form Element // -> Password $oldPassword = $this->createElement('password', 'oldPassword'); $oldPassword->setLabel('Old Password')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->setDecorators($this->elementDecorators); $this->addElement($oldPassword); // -> Password $password = $this->createElement('password', 'newPassword'); $password->setLabel('New Password')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->setDecorators($this->elementDecorators); $this->addElement($password); // -> Password Confirm // ---> Validator password $identValidator = new Zend_Validate_Identical($_POST['newPassword']); $identValidator->setMessages(array('notSame' => 'Value doesn\'t match!', 'missingToken' => 'Value doesn\'t match!')); $password2 = $this->createElement('password', 'newPassword2'); $password2->setLabel('Confirm New password:'******'StripTags')->addFilter('StringTrim')->addValidator($identValidator)->setDecorators($this->elementDecorators); $this->addElement($password2); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if a token has been set and the provided value * matches that token. * * @param mixed $value * @param mixed $context * * @return boolean */ public function isValid($value, $context = null) { if (null !== $this->_field && isset($context[$this->getField()])) { $this->setToken($context[$this->getField()]); } return parent::isValid($value, $context); }
public function testValidatingNonStrictToken() { $validator = new Zend_Validate_Identical(array('token' => 123, 'strict' => false)); $this->assertTrue($validator->isValid('123')); $validator->setStrict(true); $this->assertFalse($validator->isValid(array('token' => '123'))); }
if ($result) { $errors['username'] = '******' . $_POST['username'] . ' already exists' . '</p>'; } } // Validate password // $length->setMin(8); $val = new Zend_Validate(); $val->addValidator($length); $val->addValidator(new Zend_Validate_Alnum()); if (!$val->isValid($_POST['password'])) { $errors['password'] = '******' . 'Password must be 8-15 characters' . '</p>'; } // Confirm passwords // $val = new Zend_Validate_Identical($_POST['password']); if (!$val->isValid($_POST['conf_password'])) { $errors['conf_password'] = '******' . 'Passwords don\'t match' . '</p>'; } // Validate email // $val = new Zend_Validate_EmailAddress(); if (!$val->isValid($_POST['email'])) { $errors['email'] = '<p class="add_user_error">' . 'Invalid email address' . '</p>'; } // If all data validated, then add new user // if (!$errors) { $data = array('first_name' => $_POST['first_name'], 'surname' => $_POST['surname'], 'username' => $_POST['username'], 'email' => $_POST['email'], 'password' => sha1($_POST['password'])); $dbWrite->insert('users', $data); header('Location: login.php');
public function testCanSetTokenViaConstructor() { $validator = new Zend_Validate_Identical('foo'); $this->assertEquals('foo', $validator->getToken()); }
public function testValidatingTokenArray() { $validator = new Zend_Validate_Identical(array('token' => 123)); $this->assertTrue($validator->isValid(123)); $this->assertFalse($validator->isValid(array('token' => 123))); }
/** * Returns an array of elements for check fields during password reset and/or * 'label name' => 'required value' pairs. vor asking extra questions before allowing * a password change. * * Default is asking for the username but you can e.g. ask for someones birthday. * * @return array Of 'label name' => 'required values' or \Zend_Form_Element elements */ protected function loadResetPasswordCheckFields() { // CHECK ON SOMEONES BIRTHDAY // Birthdays are usually not defined for staff but the do exist for respondents if ($value = $this->_getVar('user_birthday')) { $label = $this->_('Your birthday'); $birthdayElem = new \Gems_JQuery_Form_Element_DatePicker('birthday'); $birthdayElem->setLabel($label)->setOptions(\MUtil_Model_Bridge_FormBridge::getFixedOptions('date'))->setStorageFormat(\Zend_Date::ISO_8601); if ($format = $birthdayElem->getDateFormat()) { $valueFormatted = \MUtil_Date::format($value, $format, $birthdayElem->getStorageFormat()); } else { $valueFormatted = $value; } $validator = new \Zend_Validate_Identical($valueFormatted); $validator->setMessage(sprintf($this->_('%s is not correct.'), $label), \Zend_Validate_Identical::NOT_SAME); $birthdayElem->addValidator($validator); return array($birthdayElem); } // */ return array($this->_('Username') => $this->getLoginName()); }
public function init() { $this->addSubForm(new LandlordsReferencing_Form_Subforms_DataProtection(), 'subform_dataprotection'); $this->setMethod('post'); //Prospective landlord name $this->addElement('select', 'title', array('label' => 'Title *', 'required' => true, 'multiOptions' => array('Mr' => 'Mr', 'Ms' => 'Ms', 'Mrs' => 'Mrs', 'Miss' => 'Miss', 'Dr' => 'Dr', 'Prof' => 'Professor', 'Sir' => 'Sir'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select your title', 'notEmptyInvalid' => 'Please select a valid title')))))); //First name entry $this->addElement('text', 'first_name', array('label' => 'First Name *', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your first name')))), 'attribs' => array('data-ctfilter' => 'yes'))); //Last name entry $this->addElement('text', 'last_name', array('label' => 'Last Name *', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your last name')))), 'attribs' => array('data-ctfilter' => 'yes'))); //Prospective landlord address details. $hiddenElement = new Zend_Form_Element_Hidden('property_number_name'); $hiddenElement->setRequired(false); $hiddenElement->clearDecorators(); $this->addElement($hiddenElement); // Add postcode element $this->addElement('text', 'property_postcode', array('label' => 'Postcode *', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter a postcode', 'notEmptyInvalid' => 'Please enter a valid postcode'))), array('regex', true, array('pattern' => '/^[0-9a-z]{2,}\\ ?[0-9a-z]{2,}$/i', 'messages' => 'Postcode must be in postcode format'))), 'attribs' => array('data-ctfilter' => 'yes'))); // Add address select element $this->addElement('select', 'property_address', array('label' => 'Please select your address *', 'required' => true, 'multiOptions' => array('' => '--- please select ---'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select your property address', 'notEmptyInvalid' => 'Please select your property address')))), 'attribs' => array('data-ctfilter' => 'yes'))); //Phone number entry $this->addElement('text', 'phone_number', array('label' => 'Telephone Number *', 'required' => true, 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your phone number'))), array('regex', true, array('pattern' => '/^((\\+44\\s?\\(0\\)\\s?\\d{2,4})|(\\+44\\s?(01|02|03|07|08)\\d{2,3})|(\\+44\\s?(1|2|3|7|8)\\d{2,3})|(\\(\\+44\\)\\s?\\d{3,4})|(\\(\\d{5}\\))|((01|02|03|07|08)\\d{2,3})|(\\d{5}))(\\s|-|.)(((\\d{3,4})(\\s|-)(\\d{3,4}))|((\\d{6,7})))$/', 'messages' => 'Not a valid phone number'))), 'attribs' => array('data-ctfilter' => 'yes'))); //Fax number entry $this->addElement('text', 'fax_number', array('label' => 'Fax Number', 'required' => false, 'validators' => array(array('regex', true, array('pattern' => '/^((\\+44\\s?\\(0\\)\\s?\\d{2,4})|(\\+44\\s?(01|02|03|07|08)\\d{2,3})|(\\+44\\s?(1|2|3|7|8)\\d{2,3})|(\\(\\+44\\)\\s?\\d{3,4})|(\\(\\d{5}\\))|((01|02|03|07|08)\\d{2,3})|(\\d{5}))(\\s|-|.)(((\\d{3,4})(\\s|-)(\\d{3,4}))|((\\d{6,7})))$/', 'messages' => 'Not a valid phone number'))), 'attribs' => array('data-ctfilter' => 'yes'))); //Mobile number entry. We do not currently capture this, so WTF do we ask for it? $this->addElement('text', 'mobile_number', array('label' => 'Mobile Number *', 'required' => true, 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your mobile number'))), array('regex', true, array('pattern' => '/^07([\\d]{3})[(\\D\\s)]?[\\d]{3}[(\\D\\s)]?[\\d]{3}$/', 'messages' => 'Not a valid mobile phone number'))), 'attribs' => array('data-ctfilter' => 'yes'))); //The email elements. $emailElement = new Zend_Form_Element_Text('email'); $emailElement->setLabel('Email *'); $emailElement->setRequired(true); $emailElement->addFilter(new Zend_Filter_StringTrim()); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please enter your email address'); $emailElement->addValidator($validator); $validator = new Zend_Validate_EmailAddress(); $validator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => "Domain name invalid in email address", Zend_Validate_EmailAddress::INVALID_FORMAT => "Invalid email address")); $emailElement->addValidator($validator); $this->addElement($emailElement); //The password element. $passwordElement = new Zend_Form_Element_Password('password'); $passwordElement->setRequired(true); $passwordElement->setLabel('Password *'); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please set a password'); $passwordElement->addValidator($validator); $passwordElement->addValidator(new Zend_Validate_PasswordStrength()); $validator = new Zend_Validate_Identical(); $validator->setToken('confirm_password'); $validator->setMessage('Passwords are not the same', Zend_Validate_Identical::NOT_SAME); $passwordElement->addValidator($validator); $this->addElement($passwordElement); //The confirm password element. $confirmPasswordElement = new Zend_Form_Element_Password('confirm_password'); $confirmPasswordElement->setRequired(true); $confirmPasswordElement->setLabel('Confirm Password *'); $validator = new Zend_Validate_NotEmpty(); $validator->setMessage('Please confirm your password'); $confirmPasswordElement->addValidator($validator); $this->addElement($confirmPasswordElement); // Security question & answer $this->addElement('select', 'security_question', array('label' => 'Security Question *', 'required' => true, 'multiOptions' => array('' => 'Please select'), 'registerInArrayValidator' => false, 'decorators' => array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false))), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please select your security question', 'notEmptyInvalid' => 'Please select your security question')))))); $this->addElement('text', 'security_answer', array('label' => 'Answer *', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter your security answer')))))); $this->addElement('text', 'insurance_renewal_date', array('label' => 'Next Landlords Insurance Renewal Date (dd/mm/yyyy)', 'required' => false, 'filters' => array('StringTrim'))); $insuranceRenewalDate = $this->getElement('insurance_renewal_date'); $validator = new Zend_Validate_DateCompare(); $validator->minimum = new Zend_Date(mktime(0, 0, 0, date('m'), date('d'), date('Y'))); // $validator->maximum = new Zend_Date(mktime(0, 0, 0, date('m'), date('d'), date('Y')) + 60 * 60 * 24 * 30); $validator->setMessages(array('msgMinimum' => 'Insurance renewal date cannot be in the past')); $insuranceRenewalDate->addValidator($validator, true); //Grab view and add the date picker JavaScript files into the page head $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $view->headLink()->appendStylesheet('/assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker.min.css', 'screen'); $view->headScript()->appendFile('/assets/vendor/jquery-date/js/date.js', 'text/javascript')->appendFile('/assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js', 'text/javascript')->appendFile('/assets/landlords-referencing/js/referencingInsuranceRenewalDatePicker.js', 'text/javascript'); //The submit button $submitElement = new Zend_Form_Element_Submit('submit'); $submitElement->setIgnore(true); $this->addElement($submitElement); //Apply decorators. This has to be done unusually for t'ings to work. $this->setElementDecorators(array(array('ViewHelper', array('escape' => false)), array('Label', array('escape' => false)))); $submitElement->removeDecorator('label'); $this->property_number_name->removeDecorator('HtmlTag'); //Grab view and add the address lookup JavaScript into the page head $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $view->headScript()->appendFile('/assets/common/js/addressLookup.js', 'text/javascript'); }
/** * Fungsi inisialisasi form */ public function init() { parent::init(); $langId = Zend_Registry::get('languageId'); if ($langId != 2) { $textrealnamereg = 'Real Name'; $textconfpassreg = 'Confirm Password'; $textcountryreg = 'Country'; $textselectcountryreg = 'Choose Country'; $textreg = 'Register'; } else { $textrealnamereg = 'Nama Asli'; $textconfpassreg = 'Konfirmasi Password'; $textcountryreg = 'Negara'; $textselectcountryreg = 'Pilih Negara Anda'; $textreg = 'Daftar'; } // Form Attribute $this->setMethod('post'); $this->addAttribs(array('id' => 'inputForm', 'action' => $this->_baseUrlHelper->baseUrl() . '/registration/index')); $this->setAttrib('accept-charset', 'utf-8'); // Element Form // -> Real Name $realName = $this->createElement('text', 'realname'); $realName->setLabel($textrealnamereg)->setRequired(true)->addValidator(new Zend_Validate_StringLength(3, 20)); $this->addElement($realName); // -> Username $username = $this->createElement('text', 'username'); $username->setLabel('Username')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator(new Zend_Validate_StringLength(3, 20))->addValidator(new Zend_Validate_Db_NoRecordExists('user', 'username')); $this->addElement($username); // -> Password $password = $this->createElement('password', 'password'); $password->setLabel('Password')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim'); $this->addElement($password); // -> Password Confirm // ---> Validator password $identValidator = new Zend_Validate_Identical($_POST['password']); $identValidator->setMessages(array('notSame' => 'Value doesn\'t match!', 'missingToken' => 'Value doesn\'t match!')); $password2 = $this->createElement('password', 'password2'); $password2->setLabel($textconfpassreg)->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator($identValidator); $this->addElement($password2); // -> Email $email = $this->createElement('text', 'email'); $email->setLabel('Email:')->setRequired(true)->addValidator(new Zend_Validate_EmailAddress())->addValidator(new Zend_Validate_Db_NoRecordExists('user', 'email')); $this->addElement($email); // -> Country // ----> Model Country $countryModel = new Model_Country(); $countryData = $countryModel->getNameCountry(); $countryData[""] = $textselectcountryreg; $country = $this->createElement('select', 'country'); $country->setLabel($textcountryreg)->setRequired(true)->setMultiOptions($countryData); $this->addElement($country); // -> Captcha $publicKey = Zend_Registry::get('recaptcha_public_key'); $privateKey = Zend_Registry::get('recaptcha_private_key'); $recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha))); $this->addElement($captcha); // -> Submit $submit = $this->createElement('submit', 'submit'); $submit->setLabel($textreg)->removeDecorator('Label'); $this->addElement($submit); }
/** * Add validation rules for the password management fields * * @param \Magento\Framework\Validator\Object $validator * @return void */ protected function _addPasswordValidation(\Magento\Framework\Validator\Object $validator) { $passwordNotEmpty = new \Zend_Validate_NotEmpty(); $passwordNotEmpty->setMessage(__('Password is required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); $minPassLength = self::MIN_PASSWORD_LENGTH; $passwordLength = new \Zend_Validate_StringLength(array('min' => $minPassLength, 'encoding' => 'UTF-8')); $passwordLength->setMessage(__('Your password must be at least %1 characters.', $minPassLength), \Zend_Validate_StringLength::TOO_SHORT); $passwordChars = new \Zend_Validate_Regex('/[a-z].*\\d|\\d.*[a-z]/iu'); $passwordChars->setMessage(__('Your password must include both numeric and alphabetic characters.'), \Zend_Validate_Regex::NOT_MATCH); $validator->addRule($passwordNotEmpty, 'password')->addRule($passwordLength, 'password')->addRule($passwordChars, 'password'); if ($this->hasPasswordConfirmation()) { $passwordConfirmation = new \Zend_Validate_Identical($this->getPasswordConfirmation()); $passwordConfirmation->setMessage(__('Your password confirmation must match your password.'), \Zend_Validate_Identical::NOT_SAME); $validator->addRule($passwordConfirmation, 'password'); } }
/** * Add user defined checkfields * * @return void */ protected function addCheckFields() { $check = 1; foreach ($this->checkFields as $label => &$value) { if ($value instanceof \Zend_Form_Element) { $element = $value; } else { if ($value) { $element = new \Zend_Form_Element_Text('check_' . $check); $element->setAllowEmpty(false); $element->setLabel($label); $validator = new \Zend_Validate_Identical($value); $validator->setMessage(sprintf($this->_('%s is not correct.'), $label), \Zend_Validate_Identical::NOT_SAME); $element->addValidator($validator); $value = $element; $check++; } else { // Nothing to check for unset($this->checkFields[$label]); continue; } } $this->addElement($element); } }