/** * Инициализация формы, установка элементов * * @see Zend_Form::init() * @return void */ public function init() { $this->setAction($this->getView()->url(array())); $this->setMethod('post'); $nickname = $this->createElement('text', 'nickname'); $nickname->setLabel('[LS_FORM_FIELD_NICKNAME]'); $nickname->addValidator('stringLength', false, array(3, 150)); $nickname->setRequired(true); $nickname->setErrorMessages(array('[LS_VALIDATION_NICKNAME_RULE]')); $nickname->setDescription('[LS_VALIDATION_NICKNAME_HINT]'); $this->addElement($nickname); $email = $this->createElement('text', 'email'); $email->setLabel('[LS_FORM_FIELD_EMAIL]'); $email->addValidator('EmailAddress', false); $email->setRequired(true); $email->setErrorMessages(array('[LS_VALIDATION_EMAIL_RULE]')); $email->setDescription('[LS_VALIDATION_EMAIL_HINT]'); $this->addElement($email); $password = $this->createElement('password', 'password'); $password->setLabel('[LS_FORM_FIELD_PASSWORD]'); $password->addValidator('stringLength', false, array(6)); $password->setRequired(true); $password->setErrorMessages(array('[LS_VALIDATION_PASSWORD_RULE]')); $password->setDescription('[LS_VALIDATION_PASSWORD_HINT]'); $this->addElement($password); $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => "[LS_FORM_FIELD_CAPTCHA]", 'captcha' => array('captcha' => 'Image', 'WordLen' => 4, 'GcFreq' => 100, 'font' => APPLICATION_PATH . '/../fonts/arial.ttf', 'ImgDir' => APPLICATION_PATH . '/../public/images/captcha/', 'ImgUrl' => $this->getView()->baseUrl() . '/images/captcha/', 'Expiration' => 300))); // $captcha->setErrorMessages(array('[LS_VALIDATION_CAPTCHA_RULE]')); $captcha->setDescription('[LS_VALIDATION_CAPTCHA_HINT]'); $this->addElement($captcha); $submit = $this->createElement('submit', 'signup', array('label' => '[LS_FORM_BUTTON_SIGNUP]')); $submit->setAttrib('class', 'button'); $this->addElement($submit); }
/** * Form initialization * * @return void */ public function init() { $this->addElementPrefixPath('Users_Form_Auth_Validate', dirname(__FILE__) . "/Validate", 'validate'); $this->setName('userRegisterForm'); $username = new Zend_Form_Element_Text('login'); $username->setLabel('User name')->addDecorators($this->_inputDecorators)->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('Alnum')->addValidator('StringLength', false, array(Users_Model_User::MIN_USERNAME_LENGTH, Users_Model_User::MAX_USERNAME_LENGTH))->addValidator('Db_NoRecordExists', false, array(array('table' => 'users', 'field' => 'login'))); $password = new Zend_Form_Element_Password('password'); $password->setLabel('Password')->addDecorators($this->_inputDecorators)->setRequired(true)->setValue(null)->addValidator('StringLength', false, array(Users_Model_User::MIN_PASSWORD_LENGTH))->addValidator('PasswordConfirmation'); $confirmPassword = new Zend_Form_Element_Password('password2'); $confirmPassword->setLabel('Password again')->addDecorators($this->_inputDecorators)->setRequired(true)->setValue(null)->addValidator('StringLength', false, array(Users_Model_User::MIN_PASSWORD_LENGTH)); $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email')->addDecorators($this->_inputDecorators)->setRequired(true)->setValue(null)->addValidator('StringLength', false, array(6))->addValidator('EmailAddress')->addValidator('Db_NoRecordExists', false, array(array('table' => 'users', 'field' => 'email'))); $imgDir = dirname(APPLICATION_PATH) . "/public/captcha"; // check captcha path is writeable if (is_writable($imgDir)) { $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => "Please verify you're a human", 'captcha' => 'Image', 'captchaOptions' => array('captcha' => 'Image', 'wordLen' => 6, 'timeout' => 300, 'imgDir' => $imgDir, 'imgUrl' => '/captcha/', 'font' => dirname(APPLICATION_PATH) . "/data/fonts/Aksent_Normal.ttf"))); } else { $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => "Please verify you're a human", 'captcha' => 'Figlet', 'captchaOptions' => array('wordLen' => 6, 'timeout' => 300))); } $captcha->addDecorators($this->_inputDecorators); $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel('Register'); $submit->setAttrib('class', 'btn btn-primary'); $this->addElements(array($username, $password, $confirmPassword, $email, $captcha, $submit)); return $this; }
/** Init the form * @return void * @access public */ public function init() { $this->setMethod('post')->setAttrib('id', 'resetpassword'); $username = $this->addElement('Text', 'username', array('label' => 'Username: '******'username')->setRequired(true)->addErrorMessage('You must enter a username')->addFilters(array('StringTrim', 'StripTags', 'Purifier'))->addValidator('Db_RecordExists', false, array('table' => 'users', 'field' => 'username')); $activationKey = $this->addElement('Text', 'activationKey', array('label' => 'Reset password key')); $activationKey = $this->getElement('activationKey')->setDescription('The reset key can be found in the email you ' . 'received when asking for a new password. ' . 'Check your spam filter')->setRequired(true)->addErrorMessage('You must enter a reset key')->addFilters(array('StringTrim', 'StripTags', 'Purifier'))->addValidator('Db_RecordExists', false, array('table' => 'users', 'field' => 'activationKey')); $password = $this->addElement('Text', 'password', array('label' => 'New password')); $password = $this->getElement('password')->setRequired(true)->setDescription('Password must be longer than 6 characters and must include letters and numbers i.e. p4ssw0rd')->addFilters(array('StringTrim', 'StripTags', 'Purifier'))->addValidator('StringLength', true, array(6))->addValidator('Regex', true, array('/^(?=.*\\d)(?=.*[a-zA-Z]).{6,}$/'))->setRequired(true)->addErrorMessage('Please enter a valid password!'); $password->getValidator('StringLength')->setMessage('Password is too short'); $password->getValidator('Regex')->setMessage('Password does not contain letters and numbers'); $email = $this->addElement('Text', 'email', array('label' => 'Email Address: ', 'size' => '30'))->email; $email->addValidator('EmailAddress')->setRequired(true)->addFilters(array('StringTrim', 'StripTags'))->addErrorMessage('Please enter a valid address!')->addValidator('Db_RecordExists', false, array('table' => 'users', 'field' => 'email')); $hash = new Zend_Form_Element_Hash('csrf'); $hash->setValue($this->_salt)->setTimeout(4800); $this->addElement($hash); $recaptcha = new Zend_Service_ReCaptcha($this->_pubKey, $this->_privateKey); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'ReCaptcha', 'label' => 'Prove you are not a robot/spammer', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha, 'theme' => 'clean', 'ssl' => true))); $captcha->setDescription('Due to the surge in robotic activity, we have had to introduce this software. However, by filling in this captcha, you help Carnegie Mellon University digitise old books.'); $captcha->setDecorators(array(array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'append', 'class' => 'error', 'tag' => 'li')))); $captcha->addErrorMessage('You have not solved the captcha'); $this->addElement($captcha); $submit = $this->addElement('submit', 'submit'); $submit = $this->getElement('submit')->setLabel('Change my password'); $this->addDisplayGroup(array('username', 'email', 'password', 'activationKey', 'captcha', 'submit'), 'details'); $this->setLegend('Reset my password: '); parent::init(); }
/** * Construtor da classe * * @see Twitter_Bootstrap_Form_Vertical * @return Auth_form_login_FormLogin|void */ public function init() { $oTradutor = $this->getTranslator(); $oBaseUrlHelper = new Zend_View_Helper_BaseUrl(); $this->setName('form_login')->setAction($oBaseUrlHelper->baseUrl('/auth/login/post')); $oElm = $this->createElement('text', 'login'); $oElm->setLabel('Login'); $oElm->setAttrib('class', 'span3'); $oElm->setAttrib('autofocus', 'autofocus'); $oElm->setRequired(TRUE); $this->addElement($oElm); $oElm = $this->createElement('password', 'senha'); $oElm->setLabel('Senha'); $oElm->setAttrib('class', 'span3'); $oElm->setRequired(TRUE); $this->addElement($oElm); $iTotalErros = 0; if ($oSessao = new Zend_Session_Namespace('captcha')) { $iTotalErros = $oSessao->errors; } if ($iTotalErros > 0) { $oKeysRecaptcha = Zend_Registry::get('config')->recaptcha; if (!empty($oKeysRecaptcha->publicKey) && !empty($oKeysRecaptcha->privateKey)) { $oRecaptcha = new Zend_Service_ReCaptcha($oKeysRecaptcha->publicKey, $oKeysRecaptcha->privateKey); $oRecaptcha->setOption('theme', 'clean'); $oCaptcha = new Zend_Form_Element_Captcha('challenge', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $oRecaptcha))); $oCaptcha->setLabel('Informe as palavras abaixo:'); $this->addElement($oCaptcha); } else { $oSessao->errors = 0; } } $this->addElement('submit', 'submit', array('label' => 'Entrar', 'class' => 'pull-right', 'data-loading-text' => $oTradutor->_('Aguarde...'), 'buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_PRIMARY)); return $this; }
public function init() { // create elements $userId = new Zend_Form_Element_Hidden('id'); $mail = new Zend_Form_Element_Text('email'); $name = new Zend_Form_Element_Text('name'); $radio = new Zend_Form_Element_Radio('radio'); $file = new Zend_Form_Element_File('file'); $multi = new Zend_Form_Element_MultiCheckbox('multi'); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'Figlet')); $submit = new Zend_Form_Element_Button('submit'); $cancel = new Zend_Form_Element_Button('cancel'); // config elements $mail->setLabel('Mail:')->setAttrib('placeholder', 'data please!')->setRequired(true)->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis fringilla purus eget ante ornare vitae iaculis est varius.')->addValidator('emailAddress'); $name->setLabel('Name:')->setRequired(true); $radio->setLabel('Radio:')->setMultiOptions(array('1' => PHP_EOL . 'test1', '2' => PHP_EOL . 'test2'))->setRequired(true); $file->setLabel('File:')->setRequired(true)->setDescription('Check file upload'); $multiOptions = array('view' => PHP_EOL . 'view', 'edit' => PHP_EOL . 'edit', 'comment' => PHP_EOL . 'comment'); $multi->setLabel('Multi:')->addValidator('Alpha')->setMultiOptions($multiOptions)->setRequired(true); $captcha->setLabel('Captcha:')->setRequired(true)->setDescription("This is a test"); $submit->setLabel('Save')->setAttrib('type', 'submit'); $cancel->setLabel('Cancel'); // add elements $this->addElements(array($userId, $mail, $name, $radio, $file, $captcha, $multi, $submit, $cancel)); // add display group $this->addDisplayGroup(array('email', 'name', 'radio', 'multi', 'file', 'captcha', 'submit', 'cancel'), 'users'); // set decorators EasyBib_Form_Decorator::setFormDecorator($this, EasyBib_Form_Decorator::BOOTSTRAP_MINIMAL, 'submit', 'cancel'); }
private function _createCaptcha() { $captchaAdapter = new Zend_Captcha_Image(); $captchaAdapter->setFont('./fonts/times.ttf')->setWordlen(5)->setLineNoiseLevel(4)->setDotNoiseLevel(20)->setMessage('Làm ơn nhập mã xác nhận.', 'badCaptcha'); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => $captchaAdapter)); $captcha->setLabel('Mã xác nhận: ')->setRequired(true); $captcha = $this->_customizeFormElement($captcha); return $captcha; }
public function init() { $Ankieta = new Application_Model_DbTable_AnkietyPytania(); $select = $Ankieta->select(array('id', 'pytanie', 'czy_obrazek'))->where('czy_wyswietlac = ?', 't')->where('sekcja = ?', 'lewa')->where('rodzaj = ?', 'normal')->order('kolejnosc DESC')->order('data_dodania DESC')->order('pytanie ASC')->limit(1); //echo $select->__toString(); $ankieda = $Ankieta->fetchAll($select); foreach ($ankieda as $pytanie) { $pytania_id[] = $pytanie->id; $pytania[] = $pytanie->pytanie; $odpowiedziFetch = $pytanie->findApplication_Model_DbTable_AnkietyOdpowiedzi(); // sortowanie $odpowiedziArray = $odpowiedziFetch->toArray(); usort($odpowiedziArray, create_function('$a, $b', 'if ($a["kolejnosc"] == $b["kolejnosc"]) return 0; return ($a["kolejnosc"] < $b["kolejnosc"]) ? -1 : 1;')); // usort($odpowiedziArray, sort_answers($a, $b){ // return strcmp($a["kolejnosc"], $b["kolejnosc"]); // });// sort foreach ($odpowiedziArray as $odpowiedz) { $odpowiedzi_id[] = $odpowiedz['id']; $odpowiedzi[] = $odpowiedz['odpowiedz']; } } $this->addElement('hidden', 'plaintext', array('description' => '<dt id="odpowiedzi-label"><h3 class="tytul">' . $pytania[0] . '</h3></dt>', 'decorators' => array(array('Description', array('escape' => false, 'tag' => ''))))); $kontrolkaRadio = new Zend_Form_Element_Radio("odpowiedzi[]", array('multiOptions' => array_combine($odpowiedzi_id, $odpowiedzi), 'registerInArrayValidator' => false, 'validators' => array('NotEmpty' => array('validator' => 'NotEmpty', 'options' => array('messages' => 'Musisz wybrać jedną odpowiedź.'))))); $kontrolkaRadio->setRequired(true); $kontrolkaRadio->removeDecorator('Label'); $kontrolkaRadio->setSeparator(false); $this->addElement($kontrolkaRadio); if ($ankieda[0]->czy_obrazek == 't') { //first create an image type captcha $captchaimg = new Zend_Captcha_Image('captchaimg'); $captchaimg->setFont(APPLICATION_PATH . '/../public/images/tresci/captcha/Tahoma.ttf'); $captchaimg->setImgDir(APPLICATION_PATH . '/../public/images/tresci/captcha'); $captchaimg->setImgUrl('/images/tresci/captcha'); $captchaimg->setWordlen('5'); $captchaimg->setMessages(array('badCaptcha' => 'Wpisany kod jest nieprawidłowy')); // $captchaimg->generate(); //create user input for captcha and include the captchaimg in form $adcaptcha = new Zend_Form_Element_Captcha('adcaptcha', array('captcha' => $captchaimg)); $adcaptcha->setLabel('Wpisz kod z obrazka:'); $adcaptcha->setRequired(true); $this->addElement($adcaptcha); } $kontrolkaSubmit = new Zend_Form_Element_Submit("submit", "Głosuj"); // $kontrolkaSubmit->removeDecorator('DtDdWrapper'); // $kontrolkaSubmit->setAttribs(array('style' => 'margin-left:130px;')); $kontrolkaSubmit->removeDecorator('Label'); $this->addElement($kontrolkaSubmit); $this->addDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'sonda-content')), array('Form', array('class' => 'sonda-form')))); //echo $pytania_id[0]; $this->setMethod('post'); //$url = $view->url(array('controller' => 'sonda', 'action' => 'edit', 'id' => $pytania_id[0]), 'default'); $url = $this->getView()->url(array('controller' => 'sonda', 'action' => 'edit', 'id' => $pytania_id[0]), 'default'); $this->setAction($url); }
public function init() { $this->setAction($this->_actionUrl)->setMethod('post')->setAttrib('id', 'registerform'); $this->addElementPrefixPath('Pas_Validate', 'Pas/Validate/', 'validate'); $this->addPrefixPath('Pas_Form_Element', 'Pas/Form/Element/', 'element'); $decorators = array(array('ViewHelper'), array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'append', 'class' => 'error', 'tag' => 'li')), array('Label', array('separator' => ' ', 'requiredSuffix' => ' *', 'class' => 'leftalign')), array('HtmlTag', array('tag' => 'li'))); $this->addElement('rawText', 'text1', array('value' => '<p class="info">By registering you agree to these <a href="#toc" rel="facebox">terms and conditions</a> of the database.</p>')); $username = $this->addElement('Text', 'username', array('label' => 'Username'))->username; $username = $this->getElement('username')->addValidator('UsernameUnique', true, array('id', 'username', 'id', 'Users'))->addValidator('StringLength', true, array(4))->addValidator('Alnum', false, array('allowWhiteSpace' => false))->setRequired(true)->addFilters(array('StringToLower', 'StringTrim', 'StripTags'))->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'username'))->setDescription('Username must be more than 3 characters and include only letters and numbers'); $username->getValidator('Alnum')->setMessage('Your username must be letters and digits only'); $username->setDecorators($decorators); $password = $this->addElement('Password', 'password', array('label' => 'Password'))->password; $password->setDescription('Password must be longer than 6 characters and must include letters and numbers i.e. p4ssw0rd')->addValidator('StringLength', true, array(6))->addValidator('Regex', true, array('/^(?=.*\\d)(?=.*[a-zA-Z]).{6,}$/'))->setRequired(true)->addErrorMessage('Please enter a valid password!'); $password->getValidator('StringLength')->setMessage('Password is too short'); $password->getValidator('Regex')->setMessage('Password does not contain letters and numbers'); $password->setDecorators($decorators); $firstName = $this->addElement('Text', 'first_name', array('label' => 'First Name', 'size' => '30'))->first_name; $firstName->setRequired(true)->addFilters(array('StringTrim', 'StripTags'))->addErrorMessage('You must enter a firstname'); $firstName->setDecorators($decorators); $lastName = $this->addElement('Text', 'last_name', array('label' => 'Last Name', 'size' => '30'))->last_name; $lastName->setRequired(true)->addFilters(array('StringTrim', 'StripTags'))->addErrorMessage('You must enter a surname'); $lastName->setDecorators($decorators); $preferredName = $this->addElement('Text', 'preferred_name', array('label' => 'Preferred Name', 'size' => '30'))->preferred_name; $preferredName->setDescription('e.g. Joe Brown rather than Joseph Brown')->setRequired(true)->addFilters(array('StringToLower', 'StringTrim', 'StripTags'))->addErrorMessage('You must enter your preferred name'); $preferredName->setDecorators($decorators); $email = $this->addElement('Text', 'email', array('label' => 'Email Address', 'size' => '30'))->email; $email->addValidator('EmailAddress', false, array('mx' => true))->setRequired(true)->addFilters(array('StringToLower', 'StringTrim', 'StripTags'))->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'email')); $email->setDecorators($decorators); $hash = new Zend_Form_Element_Hash('csrf'); $hash->setValue($this->_config->form->salt)->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->removeDecorator('label')->setTimeout(4800); $this->addElement($hash); $privateKey = $config->recaptcha->privatekey; $pubKey = $config->recaptcha->pubkey; $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'ReCaptcha', 'label' => 'Prove you are not a robot by completing this.', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'privKey' => $this->_config->webservice->recaptcha->privatekey, 'pubKey' => $this->_config->webservice->recaptcha->pubkey, 'theme' => 'clean'))); $captcha->setDescription('Due to the surge in robotic activity, we have had to introduce this software. However, by filling in this captcha, you help Carnegie Mellon University digitise old books.'); $captcha->setDecorators(array(array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'append', 'class' => 'error', 'tag' => 'li')))); $captcha->addErrorMessage('You have not solved the captcha'); $this->addElement($captcha); //Submit button $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton')->setAttrib('class', 'large')->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setLabel('Register!'); $this->addElement($submit); $this->addDisplayGroup(array('username', 'password', 'first_name', 'last_name', 'preferred_name', 'email', 'text1', 'captcha'), 'details'); $this->details->setLegend('Register with the Scheme: '); $this->removeDecorator('DtDdWrapper'); $this->removeDecorator('HtmlTag'); $this->details->removeDecorator('DtDdWrapper'); $this->addDisplayGroup(array('submit'), 'submit'); $this->submit->removeDecorator('DtDdWrapper'); $this->submit->removeDecorator('HtmlTag'); }
public function addReCaptcha($form) { $config = Zend_Registry::get("config"); $publickey = $config->recaptcha->public->key; $privatekey = $config->recaptcha->private->key; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); //Translate in your language $recaptcha_cn_translation = array('visual_challenge' => "图片验证", 'audio_challenge' => "音频验证", 'refresh_btn' => "看不清,换一张", 'instructions_visual' => "图片验证说明", 'instructions_audio' => "音频验证说明", 'help_btn' => "帮助", 'play_again' => "重放", 'cant_hear_this' => "听不到? 点这里", 'incorrect_try_again' => "验证码错误!"); $recaptcha->setOption('custom_translations', $recaptcha_cn_translation); //Change theme $recaptcha->setOption('theme', 'clean'); $captcha = new Zend_Form_Element_Captcha('challenge', array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha), 'ignore' => false)); $captcha->setRequired(true); $form->addElement($captcha); }
/** * Render form element * * @param Zend_View_Interface $view * @return string */ public function render(Zend_View_Interface $view = null) { $captcha = $this->getCaptcha(); $captcha->setName($this->getFullyQualifiedName()); if (!$this->loadDefaultDecoratorsIsDisabled()) { // fieldSize decorator mus be first $fieldSize = $this->getDecorator('FieldSize'); $this->removeDecorator('FieldSize'); // duplicated text field generated by ViewHelper decorator $this->removeDecorator('ViewHelper'); $decorators = $this->getDecorators(); $decorator = $captcha->getDecorator(); $key = get_class($this->_getDecorator($decorator, null)); if (!empty($decorator) && !array_key_exists($key, $decorators)) { array_unshift($decorators, $decorator); } $decorator = array('Captcha', array('captcha' => $captcha)); $key = get_class($this->_getDecorator($decorator[0], $decorator[1])); if ($captcha instanceof Zend_Captcha_Word && !array_key_exists($key, $decorators)) { array_unshift($decorators, $decorator); } array_unshift($decorators, $fieldSize); $this->setDecorators($decorators); } $this->setValue($this->getCaptcha()->generate()); return parent::render($view); }
public function init() { // usuario_nome $usuario_nome = new Zend_Form_Element_Text('usuario_nome'); $usuario_nome->setLabel('Nome Completo: '); $usuario_nome->setRequired(); $usuario_nome->addErrorMessages(array(Zend_Validate_NotEmpty::IS_EMPTY => "Campo obrigatório!")); $usuario_nome->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe seu nome')); $usuario_nome->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // usuario_email $usuario_email = new Zend_Form_Element_Text('usuario_email'); $usuario_email->setLabel('E-mail: '); $usuario_email->addValidator(new App_Validate_UsuarioEmail()); $usuario_email->setRequired(); $usuario_email->addValidator('EmailAddress'); $usuario_email->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe seu e-mail')); $usuario_email->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // usuario_cep $usuario_cep = new Zend_Form_Element_Text('usuario_cep'); $usuario_cep->setLabel('CEP: '); $usuario_cep->setRequired(); $usuario_cep->addValidator(new App_Validate_Cep()); $usuario_cep->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe seu CEP')); $usuario_cep->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // usuario_senha $usuario_senha = new Zend_Form_Element_Password("usuario_senha"); $usuario_senha->setLabel("Senha: "); $usuario_senha->setRequired(); $usuario_senha->setAttribs(array('class' => 'form-control', 'placeholder' => 'Informe sua senha')); $usuario_senha->setDecorators(App_Forms_Decorators::$simpleElementDecorators); // usuario_politica_termo $usuario_politica_termo = new Zend_Form_Element_Checkbox('usuario_politica_termo'); $usuario_politica_termo->setLabel(" \n Li e concordo com a \n <a href='' data-toggle='modal' data-target='#modal-politica'>Política de Privacidade</a> e \n <a href='' data-toggle='modal' data-target='#modal-termo'>Termo de Uso</a>.\n "); $usuario_politica_termo->setDecorators(App_Forms_Decorators::$checkboxElementDecorators_termo); //$usuario_politica_termo->addDecorator(); //$usuario_politica_termo->setValue(0); //$usuario_politica_termo->setCheckedValue('') ; $usuario_politica_termo->setUnCheckedValue(''); $usuario_politica_termo->setRequired(); $usuario_politica_termo->addErrorMessage('Você precisa concordar com nossa Pólitica de Privacidade e Termo de Uso'); // captcha $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => 'Informe os careacteres da imagem: ', 'class' => 'form-control', 'captcha' => array('captcha' => 'Image', 'wordLen' => 3, 'timeout' => 300, 'font' => APPLICATION_PATH . '/../public/views/fonts/Exo-SemiBold.ttf', 'imgDir' => APPLICATION_PATH . '/../public/views/captcha/', 'imgUrl' => '/../public/views/captcha/'))); $captcha->removeDecorator('ViewHelper'); $this->addElements(array($usuario_nome, $usuario_email, $usuario_cep, $usuario_senha, $usuario_politica_termo)); parent::init(); $this->getElement('submit')->setLabel('Cadastrar'); }
public function init() { /* Form Elements & Other Definitions Here ... */ $emailAddress = $this->createElement('text', 'emailAddress'); $emailAddress->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '40')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter your Email.'))))->addValidator('EmailAddress', false, array('messages' => array(Zend_Validate_EmailAddress::INVALID => 'Please enter a valid Host Name')))->addErrorMessage('Pleaes Enter Valid Email Address')->setValue('')->addFilter('StringToLower')->setRequired(true); $password = $this->createElement('password', 'password'); $password->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '20')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter your Password.')), array('StringLength', false, array(6, 20, 'messages' => array(Zend_Validate_StringLength::TOO_SHORT => 'Your password is too short(>6).', Zend_Validate_StringLength::TOO_LONG => 'Your password is too long(<20).')))))->setRequired(true)->setValue(''); $imageCaptcha = new Zend_Captcha_Image(); $imageCaptcha->setWidth(120)->setWordlen(4)->setHeight(50)->setTimeout(900)->setFontSize(20)->setGcFreq(5)->setFont('Fonts/tahoma.ttf')->setImgDir('images/captcha/')->setImgUrl('/images/captcha/')->setDotNoiseLevel(0)->setLineNoiseLevel(0); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => $imageCaptcha)); $captcha->removeDecorator('Label')->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setAttrib('style', 'position:relative;margin-top:20px')->setRequired(false); $login = $this->createElement('submit', 'login'); $login->setLabel("")->removeDecorator('DtDdWrapper')->setAttrib('class', 'submitBtnLgn login')->setIgnore(true); $InvalidAttempts = $this->createElement('hidden', 'InvalidAttempts'); $InvalidAttempts->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label'); $this->addElements(array($emailAddress, $password, $captcha, $login, $InvalidAttempts)); }
public function __construct($spec, $options = null) { $this->addPrefixPath('Monkeys_Captcha', 'Monkeys/Captcha/', 'captcha'); $options = array_merge($options, array('disableLoadDefaultDecorators' => true)); parent::__construct($spec, $options); $this->_decorator = new Monkeys_Form_Decorator_Composite(); $this->addDecorator($this->_decorator); }
/** * @return Zend_Form_Element_Captcha|Zend_Form_Element_Hidden */ protected function _captcha() { $registry = Zend_Registry::getInstance(); if (!isset($registry['captcha']) || isset($registry['captcha']) && $registry['captcha']) { $imgUrl = '/captcha'; $imgDir = PUBLIC_PATH . $imgUrl; // check captcha path is writeable if (is_writable($imgDir)) { $element = new Zend_Form_Element_Captcha('captcha', array('label' => "Please verify you're a human", 'captcha' => 'Image', 'captchaOptions' => array('captcha' => 'Image', 'wordLen' => 4, 'timeout' => 300, 'imgDir' => $imgDir, 'imgUrl' => $imgUrl, 'font' => dirname(APPLICATION_PATH) . "/data/fonts/Aksent_Normal.ttf", 'dotNoiseLevel' => 25, 'lineNoiseLevel' => 2, 'height' => 70))); } else { $element = new Zend_Form_Element_Captcha('captcha', array('label' => "Please verify you're a human", 'captcha' => 'Figlet', 'captchaOptions' => array('wordLen' => 4, 'timeout' => 300))); } $element->clearDecorators()->addDecorator('HtmlTag', array('tag' => '<div>', 'class' => 'captcha'))->addDecorator('Label')->addDecorator('Description', array('tag' => '<a>', 'class' => 'btn-reload captcha-refresh', 'title' => 'Press to reload image'))->setDescription('Reload')->addDecorator('Errors'); } else { $element = new Zend_Form_Element_Hidden('captcha'); } return $element; }
/** * Configure user form. * * @return void */ public function init() { // form config $this->setMethod('POST'); $this->setAction('/test/add'); $this->setAttrib('id', 'testForm'); /** * Add class to form for label alignment * * - Vertical .form-vertical (not required) Stacked, left-aligned labels over controls (default) * - Inline .form-inline Left-aligned label and inline-block controls for compact style * - Search .form-search Extra-rounded text input for a typical search aesthetic * - Horizontal .form-horizontal * * Use .form-horizontal to have same experience as with Bootstrap v1! */ $this->setAttrib('class', 'form-horizontal'); // create elements $userId = new Zend_Form_Element_Hidden('id'); $mail = new Zend_Form_Element_Text('email'); $name = new Zend_Form_Element_Text('name'); $radio = new Zend_Form_Element_Radio('radio'); $multi = new Zend_Form_Element_MultiCheckbox('multi'); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'Figlet')); $submit = new Zend_Form_Element_Button('submit'); $cancel = new Zend_Form_Element_Button('cancel'); // config elements $userId->addValidator('digits'); $mail->setLabel('Mail:')->setRequired(true)->addValidator('emailAddress'); $name->setLabel('Name:')->setRequired(true); $radio->setLabel('Radio:')->setMultiOptions(array('1' => PHP_EOL . 'test1', '2' => PHP_EOL . 'test2'))->setRequired(true); $multiOptions = array('view' => PHP_EOL . 'view', 'edit' => PHP_EOL . 'edit', 'comment' => PHP_EOL . 'comment'); $multi->setLabel('Multi:')->addValidator('Alpha')->setMultiOptions($multiOptions)->setRequired(true); $captcha->setLabel('Captcha:')->setRequired(true)->setDescription("This is a test"); $submit->setLabel('Save'); $cancel->setLabel('Cancel'); // add elements $this->addElements(array($userId, $mail, $name, $radio, $multi, $captcha, $submit, $cancel)); // add display group $this->addDisplayGroup(array('email', 'name', 'radio', 'multi', 'captcha', 'submit', 'cancel'), 'users'); $this->getDisplayGroup('users')->setLegend('Add User'); // set decorators EasyBib_Form_Decorator::setFormDecorator($this, EasyBib_Form_Decorator::BOOTSTRAP, 'submit', 'cancel'); }
/** Init the form * @access public * @return void */ public function init() { $username = $this->addElement('Text', 'username', array('label' => 'Username'))->username; $username = $this->getElement('username')->addValidator('UsernameUnique', true, array('id', 'username', 'id', 'Users'))->addValidator('StringLength', true, array(4))->addValidator('Alnum', false, array('allowWhiteSpace' => false))->setRequired(true)->addFilters(array('StringToLower', 'StringTrim', 'StripTags'))->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'username'))->setDescription('Username must be more than 3 characters and include only letters and numbers'); $username->getValidator('Alnum')->setMessage('Your username must be letters and digits only'); $password = $this->addElement('Password', 'password', array('label' => 'Password'))->password; $password = $this->getElement('password'); $password->setDescription('Password must be longer than 6 characters and must include letters and numbers i.e. p4ssw0rd')->addValidator('StringLength', true, array(6))->addValidator('Regex', true, array('/^(?=.*\\d)(?=.*[a-zA-Z]).{6,}$/'))->setRequired(true)->addErrorMessage('Please enter a valid password!'); $password->getValidator('StringLength')->setMessage('Password is too short'); $password->getValidator('Regex')->setMessage('Password does not contain letters and numbers'); $firstName = $this->addElement('Text', 'first_name', array('label' => 'First Name', 'size' => '30'))->first_name; $firstName = $this->getElement('first_name'); $firstName->setRequired(true)->addFilters(array('StringTrim', 'StripTags'))->addErrorMessage('You must enter a firstname'); $lastName = $this->addElement('Text', 'last_name', array('label' => 'Last Name', 'size' => '30'))->last_name; $lastName = $this->getElement('last_name'); $lastName->setRequired(true)->addFilters(array('StringTrim', 'StripTags'))->addErrorMessage('You must enter a surname'); $preferredName = $this->addElement('Text', 'preferred_name', array('label' => 'Preferred Name', 'size' => '30'))->preferred_name; $preferredName = $this->getElement('preferred_name'); $preferredName->setDescription('e.g. Joe Brown rather than Joseph Brown')->setRequired(true)->addFilters(array('StringToLower', 'StringTrim', 'StripTags'))->addErrorMessage('You must enter your preferred name'); $email = $this->addElement('Text', 'email', array('label' => 'Email Address', 'size' => '30'))->email; $email = $this->getElement('email'); $email->addValidator('EmailAddress', false, array('mx' => true))->setRequired(true)->addFilters(array('StringToLower', 'StringTrim', 'StripTags'))->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'email')); $hash = new Zend_Form_Element_Hash('csrf'); $hash->setValue($this->_salt)->setTimeout(4800); $this->addElement($hash); $recaptcha = new Zend_Service_ReCaptcha($this->_pubKey, $this->_privateKey); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'ReCaptcha', 'label' => 'Prove you are not a robot/spammer', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha, 'theme' => 'clean', 'ssl' => true))); $captcha->setDescription('Due to the surge in robotic activity, we have had to introduce this software. However, by filling in this captcha, you help Carnegie Mellon University digitise old books.'); $captcha->setDecorators(array(array('Description', array('placement' => 'append', 'class' => 'info')), array('Errors', array('placement' => 'append', 'class' => 'error', 'tag' => 'li')))); $captcha->addErrorMessage('You have not solved the captcha'); $this->addElement($captcha); //Submit button $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel('Register!'); $this->addElement($submit); $this->addDisplayGroup(array('username', 'password', 'first_name', 'last_name', 'preferred_name', 'email', 'captcha'), 'details'); $this->details->setLegend('Register with the Scheme: '); $this->addDisplayGroup(array('submit'), 'buttons'); parent::init(); }
public function init() { $this->setMethod('post'); $mail = new Zend_Form_Element_Text('mail'); $mail->setLabel('Adresse Mail')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator(new Zend_Validate_EmailAddress())->addPrefixPath('SRCustom_Form_Decorator', 'SRCustom/Form/Decorator', 'decorator')->setDecorators(array('SRInput')); $nom = new Zend_Form_Element_Text('nom'); $nom->setLabel('Identité')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addPrefixPath('SRCustom_Form_Decorator', 'SRCustom/Form/Decorator', 'decorator')->setOptions(array('class' => 'classNom'))->setDecorators(array('SRInput')); $equipe = new Zend_Form_Element_Text('equipe'); $equipe->setLabel('Equipe')->addFilter('StripTags')->addFilter('StringTrim')->addPrefixPath('SRCustom_Form_Decorator', 'SRCustom/Form/Decorator', 'decorator')->setDecorators(array('SRInput')); $sujet = new Zend_Form_Element_Text('sujet'); $sujet->setLabel('Sujet')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addPrefixPath('SRCustom_Form_Decorator', 'SRCustom/Form/Decorator', 'decorator')->setDecorators(array('SRInput')); $message = new Zend_Form_Element_Textarea('message'); $message->setLabel('Message')->setAttrib('cols', '35')->setAttrib('rows', '10')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addPrefixPath('SRCustom_Form_Decorator', 'SRCustom/Form/Decorator', 'decorator')->setDecorators(array('SRInput')); $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => "Captcha", 'description' => "Merci de recopier le code ci-contre.", 'captcha' => array("captcha" => "Image", "wordLen" => 4, "font" => "libs/comic.ttf", "fontSize" => 14, "width" => 100, "imgDir" => "libs/", "imgUrl" => "libs/", "DotNoiseLevel" => 20, "LineNoiseLevel" => 2))); $captcha->setRequired(true)->addPrefixPath('SRCustom_Form_Decorator', 'SRCustom/Form/Decorator', 'decorator')->setDecorators(array('SRCaptcha')); $envoyer = new Zend_Form_Element_Submit('envoyer'); $envoyer->setAttrib('id', 'boutonenvoyer')->setDecorators($this->buttonDecorators); $this->addElements(array($mail, $nom, $equipe, $sujet, $message, $captcha, $envoyer)); }
public function init() { $contact = array(); $contact[] = array('key' => 'email', 'value' => ' Email'); $contact[] = array('key' => 'phone', 'value' => ' Phone'); $this->setAttrib('enctype', 'multipart/form-data'); $contactName = $this->createElement('text', 'contactName'); $contactName->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '100')->setAttrib('class', 'input w90 required')->setAttrib('placeholder', 'Contact Name')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->setValue('')->setRequired(true); $address = $this->createElement('text', 'address'); $address->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '500')->setAttrib('class', 'input w90')->setAttrib('placeholder', 'Address')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields')), array('StringLength', false, array(1, 500, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'address is too long(>510).')))))->setValue('')->setRequired(false); $city = $this->createElement('text', 'city'); $city->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'input w90')->setAttrib('placeholder', 'City')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->addValidator('StringLength', false, array(1, 100))->setValue('')->setAttrib('maxlength', '100')->setRequired(false); $state = $this->createElement('text', 'state'); $state->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'uinp1')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->addValidator('StringLength', false, array(1, 200))->setValue('')->setAttrib('maxlength', '200')->setRequired(false); $country = $this->createElement('text', 'country'); $country->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'uinp1')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->addValidator('StringLength', false, array(1, 100))->setValue('')->setAttrib('maxlength', '100')->setRequired(false); $postalCode = $this->createElement('text', 'postalCode'); $postalCode->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'uinp1')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->addValidator('StringLength', false, array(1, 10))->setValue('')->setAttrib('maxlength', '10')->setRequired(false); $phone = $this->createElement('text', 'phone'); $phone->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'input w90')->setAttrib('placeholder', 'Phone')->setAttrib('maxlength', '15')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->setValue('')->setRequired(false); $emailAddress = $this->createElement('text', 'emailAddress'); $emailAddress->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '40')->setAttrib('class', 'input w90')->setAttrib('placeholder', 'Email')->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields')), array('StringLength', false, array(5, 40))))->addValidator('EmailAddress')->addFilters(array('StringTrim'))->setRequired(true); $fax = $this->createElement('text', 'fax'); $fax->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'uinp1')->setAttrib('maxlength', '15')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->setValue('')->setRequired(false); $website = $this->createElement('text', 'website'); $website->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'uinp1')->setAttrib('maxlength', '255')->addFilters(array('StringTrim'))->setValue('')->setRequired(false); $moreinfo = $this->createElement('checkbox', 'moreinfo'); $moreinfo->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'addcontact')->setRequired(false)->setChecked(false); $comments = $this->createElement('textarea', 'comments'); $comments->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '1000')->setAttrib('rows', '3')->setAttrib('cols', '25')->setAttrib('class', 'input w90 textarea')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => ' *Required fields'))))->setRequired(true); $imageCaptcha = new Zend_Captcha_Image(); $imageCaptcha->setWidth(120)->setWordlen(4)->setHeight(50)->setTimeout(900)->setFontSize(20)->setGcFreq(5)->setFont('Fonts/tahoma.ttf')->setImgDir('images/captcha/')->setImgUrl('/images/captcha/')->setDotNoiseLevel(0)->setLineNoiseLevel(0); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => $imageCaptcha)); $captcha->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('style', 'position:relative;float:left; width:200px;'); $contactType = new Zend_Form_Element_Radio('contactType'); $contactType->removeDecorator('Label')->removeDecorator('HtmlTag')->setMultiOptions($contact)->setValue('email')->setSeparator(' ')->setRequired(false); $submit = $this->createElement('button', 'submit'); $submit->removeDecorator('Label')->removeDecorator('DtDdWrapper')->setValue('Submit')->setAttrib('class', 'submitBtn')->setIgnore(true); $type = $this->createElement('hidden', 'type'); $type->removeDecorator('HtmlTag')->removeDecorator('Label'); $this->addElements(array($contactName, $address, $city, $state, $country, $postalCode, $phone, $emailAddress, $fax, $website, $moreinfo, $comments, $contactType, $type, $captcha, $submit)); }
public function init() { $this->setName('forgotpwd'); $this->setAttrib('id', 'forgotpwd'); // Add userId Id Element $userId = new Zend_Form_Element_Text('userId'); $userId->setLabel('User id :')->addFilters(array('StripTags', 'StringTrim', 'StringToLower'))->setRequired(true)->addValidator('NotEmpty')->addValidator(new Zend_Validate_Alnum(array('allowWhiteSpace' => false)))->addValidator(new Zend_Validate_StringLength(array('max' => 100, 'min' => 8))); // Add an Email Id Element $EmailId = new Zend_Form_Element_Text('email'); $EmailId->setLabel('Email :')->addFilters(array('StripTags', 'StringTrim', 'StringToLower'))->setRequired(true)->addValidator('NotEmpty')->addValidator(new Zend_Validate_EmailAddress()); $this->addElements(array($userId, $EmailId)); // create captcha $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => 'Figlet', 'captchaOptions' => array('captcha' => 'Figlet', 'wordLen' => 6, 'timeout' => 300))); $captcha->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty'); $captcha->setLabel('Verification code * :')->setOptions(array('size' => '45')); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('class', 'form-submit-button'); $this->addElements(array($captcha, $submit)); $this->setDecorators(array(array('ViewScript', array('viewScript' => 'viewscripts/forgotPwdVwScript.phtml')))); }
public function init() { //логин пользователя $txtLog = new Zend_Dojo_Form_Element_ValidationTextBox(array('name' => 'username', 'label' => 'Имя пользователя (логин) (*)', 'required' => true, 'trim' => true, 'regExp' => AuthModel::LOGIN_PARTIAL_REGEX, 'invalidMessage' => 'Допускаются символы латинского алфавита, знак подчёркивания и минус. Длина от 3 до 32х символов')); //правильный валидатор имени пользователя в соответсвии с требованиями. $txtLog->addValidator('regex', true, array(AuthModel::LOGIN_REGEX)); $txtPwd = new Zend_Dojo_Form_Element_PasswordTextBox(array('name' => 'password', 'label' => 'Пароль (проверьте текущую раскладку клавиатуры и состояние клавиши CapsLock) (*)', 'required' => true, 'regExp' => AuthModel::PWD_PARTIAL_REGEX, 'invalidMessage' => 'Пароль должен быть не менее ' . AuthModel::PWD_MIN_LEN . ' знаков и не более ' . AuthModel::PWD_MAX_LEN . ' знаков длиной')); $txtPwd->addFilter('StringTrim'); $txtPwd2 = new Zend_Dojo_Form_Element_PasswordTextBox(array('name' => 'password2', 'label' => 'Повторите пароль (*)', 'required' => true, 'regExp' => AuthModel::PWD_PARTIAL_REGEX, 'invalidMessage' => 'Повторно введённый пароль не совпадает с исходным!')); $txtPwd2->addFilter('StringTrim'); $txtEmail = new Zend_Dojo_Form_Element_ValidationTextBox(array('name' => 'email', 'label' => 'Электронная почта (*). Используется только внутри сайта для получения уведомлений о новых комментариях, смены пароля и прочих служебных действий. Третьим лицам не передаётся.', 'required' => true, 'trim' => true, 'regExp' => AuthModel::EMAIL_PARTIAL_REGEX, 'invalidMessage' => 'Вероятно, введённая строка не явлется адресом почты. Укажите правильный адрес')); $txtEmail->addFilter('StringToLower'); $txtEmail->addValidator('StringLength', true, array(0, AuthModel::EMAIL_MAX_LEN))->addValidator('EmailAddress', true); $bShowEmail = new Zend_Dojo_Form_Element_CheckBox(array('name' => 'bshowemail', 'label' => 'Показывать другим пользователям Ваш email?', 'checkedValue' => '1', 'uncheckedValue' => '0', 'checked' => false)); $bShowEmail->addValidator('regex', true, array('/^0|1$/')); $txtName = new Zend_Dojo_Form_Element_ValidationTextBox(array('name' => 'name', 'label' => 'Ваше имя', 'trim' => true, 'regExp' => '^.{0,' . AuthModel::NAME_MAX_LEN . '}$', 'invalidMessage' => 'Длина поля ограничена ' . AuthModel::NAME_MAX_LEN . ' символами')); $txtName->addValidators(array(array(new Zend_Validate_StringLength(0, AuthModel::NAME_MAX_LEN), true))); //страна $txtCountry = new Zend_Dojo_Form_Element_ValidationTextBox(array('name' => 'country', 'label' => 'Страна', 'trim' => true, 'regExp' => '^.{0,' . AuthModel::VAR_FIELD_MAX_LEN . '}$', 'invalidMessage' => 'Длина поля ограничена ' . AuthModel::VAR_FIELD_MAX_LEN . ' символами')); $varFieldLengthVld = array(new Zend_Validate_StringLength(0, AuthModel::VAR_FIELD_MAX_LEN), true); $txtCountry->addValidators(array($varFieldLengthVld)); $txtCity = new Zend_Dojo_Form_Element_ValidationTextBox(array('name' => 'city', 'label' => 'Город', 'trim' => true, 'regExp' => '^.{0,' . AuthModel::VAR_FIELD_MAX_LEN . '}$', 'invalidMessage' => 'Длина поля ограничена ' . AuthModel::VAR_FIELD_MAX_LEN . ' символами')); $txtCity->addValidators(array($varFieldLengthVld)); $birthday = new Zend_Dojo_Form_Element_DateTextBox(array('name' => 'birthday', 'label' => 'Ваш день рождения', 'invalidMessage' => 'Указана неверная дата', 'formatLength' => 'long')); $birthday->addValidator('Date', true); $cIcq = new Zend_Dojo_Form_Element_ValidationTextBox(array('name' => 'cicq', 'label' => 'Номер ICQ', 'trim' => true, 'regExp' => '^\\d{0,' . AuthModel::ICQNUM_MAX_CHARS . '}$', 'invalidMessage' => 'Номер ICQ должен являться числом')); $cIcq->addValidators(array(array('StringLength', true, array(0, AuthModel::ICQNUM_MAX_CHARS)), array('Digits', true))); $cSkype = new Zend_Dojo_Form_Element_TextBox(array('name' => 'cskype', 'label' => 'Skype', 'trim' => true)); $cSkype->addValidators(array($varFieldLengthVld)); $captcha = new Zend_Form_Element_Captcha('turingtest', array('label' => "Captcha", 'captcha' => 'ReCaptcha', 'captchaOptions' => array('privKey' => '6Lf9xQMAAAAAAGt9yhFNmsuemMpAzefPc0qDrxmo', 'pubKey' => '6Lf9xQMAAAAAAN9DCeBc_x8ZAK7hKtQrozTF6KAa'))); //делаем язык. через жопу $captcha->getCaptcha()->getService()->setOption('lang', 'ru'); $btnSubmit = new Zend_Dojo_Form_Element_SubmitButton(array('name' => 'register', 'label' => 'Register!')); //добавляем onSubmit, потому что требуется там ручками обрабатывать значение чекбокса - оно почему-то не меняется. //задаём проверочную функцию $this->setAttrib('onsubmit', "dojo.byId('bshowemail').value = dijit.byId('bshowemail').attr('checked') ? '1' : '0'; return true;"); $this->setAttrib('id', 'regForm'); $this->addElements(array($txtLog, $txtPwd, $txtPwd2, $txtEmail, $bShowEmail, $txtName, $txtCountry, $txtCity, $birthday, $cIcq, $cSkype, $captcha, $btnSubmit)); }
/** * * Activate account form * */ public function init() { $cname = explode('_', get_class()); $this->preInit(end($cname), true, false); // use template file $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/ActivateAccount.phtml')))); // fields $confirm = new Zend_Form_Element_Checkbox('confirm'); $confirm->setDecorators(array('ViewHelper', 'Errors'))->setLabel($this->translator->translate('Accept Terms & Conditions'))->addValidator('GreaterThan', false, array(0))->setErrorMessages(array($this->translator->translate('Please Read and Agree to our Terms & Conditions'))); $register = new Zend_Form_Element_Submit('activatesubmit'); $register->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Create Account'))->setAttrib('class', 'submit btn btn-default'); if (Zend_Registry::get('config')->get('recaptcha_active') == 1) { $privateKey = Zend_Registry::get('config')->get('recaptcha_privatekey'); $publicKey = Zend_Registry::get('config')->get('recaptcha_publickey'); $recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey, array('ssl' => true)); $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => '', 'captcha' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha))); $captcha->setDecorators(array('ViewHelper', 'Errors')); $this->addElements(array($captcha, $confirm, $register)); } else { $this->addElements(array($confirm, $register)); } $this->postInit(); }
public function __construct($action, $options = null) { parent::__construct($options); $this->setName('postcomment')->setAction($action)->setMethod('post')->setAttrib('id', 'postcomment'); # author $authorValidatorDB = new FansubCMS_Validator_NoRecordExists('User_Model_User', 'name'); $authorValidatorDB->setMessages(array(FansubCMS_Validator_NoRecordExists::RECORD_EXISTS => 'news_comment_form_error_author_user_exists')); $author = $this->createElement('text', 'author'); $author->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'default_form_error_empty_value')))->addValidator('stringLength', true, array('min' => 3, 'max' => 32, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'news_comment_form_error_author_length', Zend_Validate_StringLength::TOO_SHORT => 'news_comment_form_error_author_length')))->addValidator($authorValidatorDB)->setRequired(true)->setLabel('news_comment_field_author'); # email $email = $this->createElement('text', 'email'); $email->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'default_form_error_empty_value')))->addFilter('StripTags')->addFilter('StringTrim')->addValidator('EmailAddress', false, array('allow' => Zend_Validate_Hostname::ALLOW_DNS, 'domain' => true, 'messages' => array(Zend_Validate_EmailAddress::DOT_ATOM => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_FORMAT => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_LOCAL_PART => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'default_form_error_email', Zend_Validate_EmailAddress::INVALID_SEGMENT => 'default_form_error_email', Zend_Validate_EmailAddress::LENGTH_EXCEEDED => 'default_form_error_email', Zend_Validate_EmailAddress::QUOTED_STRING => 'default_form_error_email')))->setRequired(true)->setLabel('news_comment_field_email'); # url $url = $this->createElement('text', 'url'); $url->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->setLabel('news_comment_field_website'); # comment $comment = $this->createElement('Textarea', 'comment'); $comment->setRequired(true)->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'default_form_error_empty_value')))->setAttrib('rows', 15)->setAttrib('cols', 40)->setLabel('news_comment_field_text'); #captcha if (!User_Model_User::isLoggedIn()) { $imgUrl = substr($_SERVER['PHP_SELF'], 0, -9) . '/media/common/images/tmp'; // little hack to have the correct baseurl $imgUrl = str_replace('//', '/', $imgUrl); $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => 'captcha', 'captcha' => array('captcha' => 'Image', 'wordLen' => 6, 'timeout' => 300, 'height' => 80, 'width' => 150, 'startImage' => null, 'font' => realpath(APPLICATION_PATH . '/data/ttf') . '/captcha.ttf', 'imgurl' => $imgUrl, 'imgDir' => HTTP_PATH . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tmp'), 'errorMessages' => array('default_form_error_captcha_wrong'))); $captcha->setRequired(true); } # add elements to the form if (!User_Model_User::isLoggedIn()) { $this->addElement($author)->addElement($email); } $this->addElement($url)->addElement($comment); if (!User_Model_User::isLoggedIn()) { $this->addElement($captcha); } # commit button $this->addElement('submit', 'submit', array('label' => 'news_comment_field_submit', 'class' => 'button')); }
public function __construct($spec, $options = null) { $view = Zend_Layout::getMvcInstance()->getView(); $options = array('captcha' => array('captcha' => 'Image', 'wordLen' => 5, 'timeout' => 300, 'fontsize' => 25, 'font' => APPLICATION_PATH . '/../public/fonts/Verdana.ttf', 'imgDir' => APPLICATION_PATH . '/../public/img/captcha/', 'imgUrl' => $view->baseUrl() . '/img/captcha/', 'ImgAlt' => 'Captcha', 'ImgAlign' => 'left', 'width' => '200', 'height' => '69', 'dotNoiseLevel' => 50, 'lineNoiseLevel' => 5)); parent::__construct($spec, $options); }
/** * @group ZF-11609 */ public function testIndividualDecoratorsBeforeAndAfterRendering() { // Disable default decorators is true $element = new Zend_Form_Element_Captcha('foo', array('captcha' => 'Dumb', 'captchaOptions' => array('sessionClass' => 'Zend_Form_Element_CaptchaTest_SessionContainer'), 'disableLoadDefaultDecorators' => true, 'decorators' => array('Description', 'Errors', 'Captcha_Word', 'Captcha', 'Label'))); // Before rendering $decorators = array_keys($element->getDecorators()); $this->assertSame(array('Zend_Form_Decorator_Description', 'Zend_Form_Decorator_Errors', 'Zend_Form_Decorator_Captcha_Word', 'Zend_Form_Decorator_Captcha', 'Zend_Form_Decorator_Label'), $decorators, var_export($decorators, true)); $element->render(); // After rendering $decorators = array_keys($element->getDecorators()); $this->assertSame(array('Zend_Form_Decorator_Description', 'Zend_Form_Decorator_Errors', 'Zend_Form_Decorator_Captcha_Word', 'Zend_Form_Decorator_Captcha', 'Zend_Form_Decorator_Label'), $decorators, var_export($decorators, true)); // Disable default decorators is false $element = new Zend_Form_Element_Captcha('foo', array('captcha' => 'Dumb', 'captchaOptions' => array('sessionClass' => 'Zend_Form_Element_CaptchaTest_SessionContainer'), 'decorators' => array('Description', 'Errors', 'Captcha_Word', 'Captcha', 'Label'))); // Before rendering $decorators = array_keys($element->getDecorators()); $this->assertSame(array('Zend_Form_Decorator_Description', 'Zend_Form_Decorator_Errors', 'Zend_Form_Decorator_Captcha_Word', 'Zend_Form_Decorator_Captcha', 'Zend_Form_Decorator_Label'), $decorators, var_export($decorators, true)); $element->render(); // After rendering $decorators = array_keys($element->getDecorators()); $this->assertSame(array('Zend_Form_Decorator_Description', 'Zend_Form_Decorator_Errors', 'Zend_Form_Decorator_Captcha_Word', 'Zend_Form_Decorator_Captcha', 'Zend_Form_Decorator_Label'), $decorators, var_export($decorators, true)); }
/** * Creates the captcha element. * * @return Zend_Form_Element */ protected function createCaptcha() { $captcha = new Zend_Form_Element_Captcha($this->captchaOptions); if ($this->getOption('generateId', false)) { // Generate a unique element ID to avoid clashes if two // captchas are rendered on the same page. $captcha->setAttrib('id', $captcha->getId() . '-' . uniqid()); } return $captcha; }
public function init() { $passwordConfirm = new Rdine_Validate_PasswordConfirmation(); $salutionList = array(array('key' => 'Mr', 'value' => 'Mr'), array('key' => 'Ms', 'value' => 'Ms'), array('key' => 'Mrs', 'value' => 'Mrs')); $gengerList = array(array('key' => 'Male', 'value' => 'Male'), array('key' => 'Female', 'value' => 'Female')); $emailAddress = $this->createElement('text', 'emailAddress'); $emailAddress->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '40')->setAttrib('class', 'inp1')->setAttrib('placeholder', 'Email Address*')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter your EmailAddress.'))))->addValidator('StringLength', false, array(5, 50))->addValidator('EmailAddress', false, array('messages' => array(Zend_Validate_EmailAddress::INVALID => 'Please enter a valid Host Name')))->addErrorMessage('Pleaes Enter Valid Email Address')->addFilters(array('StringTrim'))->setValue('')->addFilter('StringToLower')->setRequired(true); $password = $this->createElement('password', 'password'); $password->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '20')->setAttrib('class', 'inp1')->setAttrib('placeholder', 'Password*')->addValidators(array($passwordConfirm, array('NotEmpty', true, array('messages' => 'Please enter your Password.')), array('StringLength', false, array(6, 20, 'messages' => array(Zend_Validate_StringLength::TOO_SHORT => 'Your password is too short(>6).', Zend_Validate_StringLength::TOO_LONG => 'Your password is too long(<20).')))))->setRequired(true)->setValue('')->setIgnore(false); $confirmPassword = $this->createElement('password', 'password_confirm'); $confirmPassword->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '20')->setAttrib('class', 'inp1')->setAttrib('placeholder', 'Confirm Password*')->addValidators(array($passwordConfirm, array('NotEmpty', true, array('messages' => 'Please enter confirm Password.'))))->setRequired(true)->setValue('')->setIgnore(false); $salution = $this->createElement('select', 'salution'); $salution->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'sel2')->addMultiOptions($salutionList)->setRequired(false); $firstName = $this->createElement('text', 'firstName'); $firstName->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '30')->setAttrib('class', 'inp1')->setAttrib('placeholder', 'First Name*')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter FirstName.')), array('Alnum')))->setValue('')->setRequired(true); $lastName = $this->createElement('text', 'lastName'); $lastName->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '30')->setAttrib('class', 'inp1')->setAttrib('placeholder', 'Last Name')->addFilters(array('StringTrim'))->addValidators(array(array('StringLength', false, array(0, 30)), array('Alnum')))->setValue('')->setRequired(false); // $gender = $this->createElement('select','gender'); // $gender->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('class', 'sel2') // ->addMultiOptions($gengerList) // ->setRequired(false); $address = $this->createElement('textarea', 'address', array('rows' => '1', 'cols' => '22')); $address->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '200')->setAttrib('class', 'inp1')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter your Address.'))))->addValidator('StringLength', false, array(1, 200, 'messages' => array(Zend_Validate_StringLength::TOO_SHORT => 'address should be minimum 10 charactors', Zend_Validate_StringLength::TOO_LONG => 'address is too long(>200).')))->addFilters(array('StringTrim'))->setValue('')->setRequired(false); // $city = $this->createElement('select', 'city'); // $city->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('class', 'sel1') // ->addValidators(array // (array('NotEmpty', true, array('messages' => 'Please select City.')))) // ->setRegisterInArrayValidator(false) // ->setRequired(true); // // // $neighborhood = $this->createElement('select','neighborhood'); // $neighborhood->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('class', 'sel1') // ->addValidators(array // (array('NotEmpty', true, array('messages' => 'Please select Neighborhood.')))) // ->setRegisterInArrayValidator(false) // ->setRequired(true); // // // $region = $this->createElement('select','region'); // $region->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('class', 'sel1') // ->addValidators(array // (array('NotEmpty', true, array('messages' => 'Please select Region.')))) // ->setRegisterInArrayValidator(false) // ->setRequired(true); // // $state = $this->createElement('select','state'); // $state->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('class', 'sel1') // ->addValidators(array // (array('NotEmpty', true, array('messages' => 'Please select State.')))) // ->addMultiOptions($stateList) // ->setRequired(true); // // $timezone = $this->createElement('select','timezone'); // $timezone->removeDecorator('label') // ->removeDecorator('HtmlTag') // ->setAttrib('class','sel1') // ->addValidators(array // (array('NotEmpty', true, array('messages' => 'Please select TimeZone.')))) // ->addMultiOptions($timezoneList) // ->setRequired(true); $postalCode = $this->createElement('text', 'postalCode'); $postalCode->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '10')->setAttrib('class', 'inp1')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter Zipcode.'))))->setValue('')->setRequired(false); $countryCode = $this->createElement('text', 'countryCode'); $countryCode->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('style', 'width:116px; float:left')->setAttrib('placeholder', 'Code')->addFilters(array('StringTrim'))->setAttrib('placeholder', 'Code')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please select country code.'))))->setValue('')->setAttrib('maxlength', '5')->setRequired(false); $phone = $this->createElement('text', 'phone'); $phone->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('style', 'float:right;')->setAttrib('placeholder', 'Phone*')->setAttrib('maxlength', '15')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter Your Phone Number.'))))->addValidator('regex', false, array('pattern' => '/^[0-9 ]+$/', 'messages' => 'Enter a valid Phone Number'))->setValue('')->setRequired(false); $mobile = $this->createElement('text', 'mobile'); $mobile->removeDecorator('Label')->removeDecorator('HtmlTag')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '15')->addFilters(array('StringTrim'))->setValue(''); // $favoritefood = $this->createElement('textArea', 'favoritefood'); // $favoritefood->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('maxlength', '1000') // ->setAttrib('cols', '40') // ->setAttrib('rows', '4') // ->addFilters(array('StringTrim')) // ->setValue(''); // // $favoritemusic = $this->createElement('textArea', 'favoritemusic'); // $favoritemusic->removeDecorator('label') // ->removeDecorator('HtmlTag') // ->setAttrib('cols', '40') // ->setAttrib('rows', '4') // ->setAttrib('maxlength', '1000') // ->addFilters(array('StringTrim')) // ->setvalue('') // ->setrequired(false); $imageCaptcha = new Zend_Captcha_Image(); $imageCaptcha->setWidth(120)->setWordlen(4)->setHeight(50)->setTimeout(900)->setFontSize(20)->setGcFreq(5)->setFont('Fonts/tahoma.ttf')->setImgDir('images/captcha/')->setImgUrl('/images/captcha/')->setDotNoiseLevel(0)->setLineNoiseLevel(0); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => $imageCaptcha)); $captcha->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setAttrib('style', 'position:relative;margin-top:-10px;width:182px;'); $register = $this->createElement('submit', 'register'); $register->setLabel("Register")->removeDecorator('DtDdWrapper')->setAttrib('class', 'submitBtn')->setIgnore(true); $reset = $this->createElement('reset', 'reset'); $reset->removeDecorator('Label')->removeDecorator('DtDdWrapper')->setLabel("Reset")->setAttrib('class', 'submitBtn')->setIgnore(true); $this->addElements(array($emailAddress, $password, $confirmPassword, $salution, $firstName, $lastName, $address, $postalCode, $phone, $countryCode, $mobile, $register, $reset, $captcha)); }
/** * Форма регистрации пользователей * * @return Zend_Form */ public function getSignupForm() { // Имя пользователя $username = new Zend_Form_Element_Text("username"); $username->setRequired(true)->addValidator("NotEmpty", true, array("messages" => array("isEmpty" => $this->_translate->_("Не заполнено имя пользователя"))))->addValidator("Callback", true, array("callback" => array($this, "validateUsernameExist"), "messages" => array("callbackValue" => $this->_translate->_("Пользователь с таким именем уже зарегистрирован"))))->setLabel($this->_translate->_("Выберите имя пользователя")); // Пароль $passw = new Zend_Form_Element_Password("passw"); $passw->setRequired(true)->addValidator("NotEmpty", true, array("messages" => array("isEmpty" => $this->_translate->_("Не выбран пароль"))))->setLabel($this->_translate->_("Выберите пароль")); // Подтверждение пароля $repassw = new Zend_Form_Element_Password("repassw"); $repassw->setRequired(true)->addValidator("NotEmpty", true, array("messages" => array("isEmpty" => $this->_translate->_("Не подтвержден пароль"))))->addValidator("Callback", true, array("callback" => array($this, "validatePasswConfirm"), "messages" => array("callbackValue" => $this->_translate->_("Неверно подтвержден пароль"))))->setLabel($this->_translate->_("Подтвердите пароль")); // Email $email = new Zend_Form_Element_Text("email"); $email->setRequired(true)->addValidator("NotEmpty", true, array("messages" => array("isEmpty" => $this->_translate->_("Не указан адрес электронной почты"))))->addValidator("EmailAddress", true, array("messages" => array("emailAddressInvalid" => $this->_translate->_("Неверно указан адрес электронной почты"), "emailAddressInvalidFormat" => $this->_translate->_("Адрес электронной почты имеет неверный формат"))))->addValidator("Callback", true, array("callback" => array($this, "validateEmailExist"), "messages" => array("callbackValue" => $this->_translate->_("Пользователь с таким email уже зарегистрирован"))))->setLabel($this->_translate->_("Адрес электронной почты")); // Подтверждение email $reemail = new Zend_Form_Element_Text("reemail"); $reemail->setRequired(true)->addValidator("NotEmpty", true, array("messages" => array("isEmpty" => $this->_translate->_("Не подтвержден адрес электронной почты"))))->addValidator("Callback", true, array("callback" => array($this, "validateEmailConfirm"), "messages" => array("callbackValue" => $this->_translate->_("Неверно подтвержден адрес электронной почты"))))->setLabel($this->_translate->_("Подтвердите адрес электронной почты")); // CAPTCHA $captcha = Phorm_Captcha_Image::getCaptcha(); $captcha->setOptions(array("messages" => array("badCaptcha" => $this->_translate->_("Неверно указан код подтверждения"), "missingID" => $this->_translate->_("Неверный идентификатор Captcha")))); $captcha = new Zend_Form_Element_Captcha("captcha", array("captcha" => $captcha)); $captcha->setLabel($this->_translate->_("Код подтверждения"))->setDescription($this->_translate->_("Введите данные с изображения (цифры и латинские буквы)")); // Создаем объект формы и добавляем в нее элементы $form = Phorm_Form::makeForm(); $form->addElement($username)->addElement($passw)->addElement($repassw)->addElement($email)->addElement($reemail)->addElement($captcha); $form->addElement(new Zend_Form_Element_Submit("Send", $this->_translate->_("Зарегистрировать"))); return $form; }
public function init() { $stateMapper = new Application_Model_CountrybdMapper(); $states = $stateMapper->fetchAll(); $stateList = array(); $stateList[] = array('key' => '', 'value' => 'Select Country'); foreach ($states as $state) { $stateList[] = array('key' => $state->getId(), 'value' => $state->getDescription()); } $stateList[] = array('key' => 'find', 'value' => 'cant find your Country'); $sourceofrestaurantMapper = new Application_Model_SourceofRestaurantDataMapper(); $sources = $sourceofrestaurantMapper->fetchAll(); $sourceList = array(); $sourceList[] = array('key' => '', 'value' => 'Select Source'); foreach ($sources as $source) { $sourceList[] = array('key' => $source->getId(), 'value' => $source->getDescription()); } $passwordConfirm = new Rdine_Validate_PasswordConfirmation(); // $confirmEmail = new Rdine_Validate_EMailConfirmation(); $emailAddress = $this->createElement('text', 'emailAddress'); $emailAddress->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '40')->setAttrib('title', 'Email Address')->setAttrib('placeholder', 'Email Address*')->addValidator('NotEmpty', true, array('messages' => 'Please enter your EmailAddress.'))->addValidator('EmailAddress', false, array('messages' => array(Zend_Validate_EmailAddress::INVALID => 'Please enter a valid Host Name')))->addErrorMessage('Pleaes Enter Valid Email Address')->addFilters(array('StringTrim'))->setValue('')->addFilter('StringToLower')->setRequired(true); // $confirmEmailAdd = $this->createElement('text', 'confirmEmailAddress'); // $confirmEmailAdd->removeDecorator('Label') // ->removeDecorator('HtmlTag') // ->setAttrib('class','inp1') // ->setAttrib('maxlength', '40') // ->setAttrib('title', 'Confirm Email Address') // ->setAttrib('placeholder', 'Confirm Email Address*') // ->addValidators(array($confirmEmail, // array('NotEmpty', true, array('messages' => 'Please confirm your EmailAddress.')) // )) // ->setValue('') // ->addFilters(array('StringTrim')) // ->addFilter('StringToLower') // ->setRequired(true); $password = $this->createElement('password', 'password'); $password->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '20')->setAttrib('title', 'Password')->setAttrib('placeholder', 'Password*')->addValidators(array($passwordConfirm, array('NotEmpty', true, array('messages' => 'Please enter your Password.')), array('StringLength', false, array(6, 20, 'messages' => array(Zend_Validate_StringLength::TOO_SHORT => 'Your password is too short(>6).', Zend_Validate_StringLength::TOO_LONG => 'Your password is too long(<20).')))))->setRequired(true)->setValue(''); $confirmPassword = $this->createElement('password', 'password_confirm'); $confirmPassword->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '20')->setAttrib('title', 'Confirm Password')->setAttrib('placeholder', 'Confirm Password*')->addValidators(array($passwordConfirm, array('NotEmpty', true, array('messages' => 'Please Confirm your password.'))))->setRequired(true)->setValue(''); $firstName = $this->createElement('text', 'firstName'); $firstName->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'First Name')->setAttrib('placeholder', 'First Name*')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter FirstName.')), array('StringLength', false, array(0, 30))))->setValue('')->setRequired(true); $lastName = $this->createElement('text', 'lastName'); $lastName->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '30')->addFilters(array('StringTrim'))->setAttrib('title', 'Last Name')->setAttrib('placeholder', 'Last Name')->addValidators(array(array('StringLength', false, array(0, 30))))->setAttrib('class', 'inp1')->setValue('')->setRequired(false); $countryCode = $this->createElement('text', 'countryCode'); $countryCode->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('style', 'width:116px; float:left')->setAttrib('readonly', 'readonly')->setAttrib('placeholder', 'Code')->setAttrib('title', 'Country Code')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please select country code.'))))->setValue('')->setAttrib('maxlength', '5')->setRequired(false); $phone = $this->createElement('text', 'phone'); $phone->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '10')->setAttrib('title', 'Phone')->setAttrib('style', 'width:325px; float:right;')->setAttrib('placeholder', 'Phone*')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter Your Phone Number.'))))->addValidator('regex', false, array('pattern' => '/^[0-9 ]+$/', 'messages' => 'Enter a valid Phone Number'))->setValue('')->setRequired(false); $rastaurantname = $this->createElement('text', 'restaurantName'); $rastaurantname->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '225')->setAttrib('title', 'Restaurant/Group')->setAttrib('placeholder', 'Restaurant/Group*')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter RestaurantName.'))))->setvalue('')->setrequired(true); $resownercountry = $this->createElement('text', 'resownercountry'); $resownercountry->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'Country')->setAttrib('placeholder', 'Country*')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter Country.')), array('StringLength', false, array(0, 30)), array('Alnum')))->setValue('')->setRequired(false); $resownercity = $this->createElement('text', 'resownercity'); $resownercity->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'City')->setAttrib('placeholder', 'City*')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter City.')), array('StringLength', false, array(0, 30))))->setValue('')->setRequired(false); $resownerzipcode = $this->createElement('text', 'resownerzipcode'); $resownerzipcode->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '10')->setAttrib('title', 'Zipcode')->setAttrib('placeholder', 'Zipcode')->addFilters(array('StringTrim'))->addValidators(array(array('NotEmpty', true, array('messages' => 'Please enter Zipcode.')), array('StringLength', false, array(0, 10)), array('Alnum')))->setValue('')->setRequired(false); $region = $this->createElement('select', 'region'); $region->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'sel1')->setAttrib('title', 'State')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please select Region.'))))->setRegisterInArrayValidator(false)->setRequired(true); $state = $this->createElement('select', 'state'); $state->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'sel1')->setAttrib('title', 'Country')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please select State.'))))->addMultiOptions($stateList)->setRequired(true); $source = $this->createElement('select', 'source'); $source->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'sel1')->setAttrib('title', 'How did you hear about us?')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please select source.'))))->addMultiOptions($sourceList)->setRequired(false); $sourcedescription = $this->createElement('textarea', 'sourcedescription'); $sourcedescription->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '5000')->setAttrib('cols', '40')->setAttrib('rows', '4')->setAttrib('class', 'inp1')->setAttrib('title', 'Source Description')->setAttrib('placeholder', 'Would you like to provide more information')->setValue('')->addValidators(array(array('StringLength', false, array(1, 200, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'Description is too long(>5000).')))))->setRequired(false); $city = $this->createElement('select', 'city'); $city->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'sel1')->setAttrib('title', 'City')->addValidators(array(array('NotEmpty', true, array('messages' => 'Please select City.'))))->setRegisterInArrayValidator(false)->setRequired(true); $cantfind = $this->createElement('hidden', 'cantfind'); $cantfind->removeDecorator('HtmlTag')->removeDecorator('Label'); $cantfindcity = $this->createElement('text', 'cantfindcity'); $cantfindcity->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'Cant Find City')->setAttrib('placeholder', 'Enter Your City')->addValidators(array(array('StringLength', false, array(0, 30))))->setValue('')->setRequired(false); $cantfindstate = $this->createElement('text', 'cantfindstate'); $cantfindstate->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'Cant Find Country')->setAttrib('placeholder', 'Enter Your Country')->addValidators(array(array('StringLength', false, array(0, 30))))->setValue('')->setRequired(false); $cantfindregion = $this->createElement('text', 'cantfindregion'); $cantfindregion->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'Cant Find State')->setAttrib('placeholder', 'Enter Your State')->addValidators(array(array('StringLength', false, array(0, 30))))->setValue('')->setRequired(false); $description = $this->createElement('textarea', 'description'); $description->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('maxlength', '5000')->setAttrib('cols', '40')->setAttrib('rows', '4')->setAttrib('class', 'inp1')->setAttrib('title', 'Description')->setAttrib('placeholder', 'Enter your comments')->setValue('')->addValidators(array(array('StringLength', false, array(1, 5000, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'Description is too long(>5000).')))))->setRequired(false); $website = $this->createElement('text', 'website'); $website->removeDecorator('Label')->removeDecorator('HtmlTag')->setAttrib('class', 'inp1')->setAttrib('maxlength', '30')->setAttrib('title', 'Website')->setAttrib('placeholder', 'Website')->addValidators(array(array('StringLength', false, array(0, 30))))->setValue('')->setRequired(false); $dateofbirth = $this->createElement('text', 'dateofbirth'); $dateofbirth->removeDecorator('Label')->setAttrib('class', 'inp1 datepicker')->removeDecorator('HtmlTag')->setAttrib('title', 'Date of Birth')->setAttrib('placeholder', 'Date of Birth')->addFilters(array('StringTrim'))->setValue(''); $imageCaptcha = new Zend_Captcha_Image(); $imageCaptcha->setWidth(200)->setWordlen(4)->setHeight(50)->setTimeout(900)->setFontSize(20)->setGcFreq(5)->setFont('Fonts/tahoma.ttf')->setImgDir('images/captcha/')->setImgUrl('/images/captcha/')->setDotNoiseLevel(0)->setLineNoiseLevel(0); $captcha = new Zend_Form_Element_Captcha('captcha', array('captcha' => $imageCaptcha)); $captcha->removeDecorator('DtDdWrapper')->removeDecorator('HtmlTag')->setAttrib('title', 'Captcha')->setAttrib('placeholder', 'Enter characters as shown in box *')->setAttrib('style', 'position:relative;margin-top:-10px;width:182px;'); $register = $this->createElement('submit', 'register'); $register->setLabel("Register")->removeDecorator('DtDdWrapper')->setAttrib('class', 'submitBtn')->setIgnore(true); $reset = $this->createElement('reset', 'reset'); $reset->removeDecorator('Label')->removeDecorator('DtDdWrapper')->setLabel("Reset")->setAttrib('class', 'submitBtn')->setIgnore(true); $comapnyid = $this->createElement('hidden', 'comapnyid'); $comapnyid->removeDecorator('HtmlTag')->removeDecorator('Label')->removeDecorator('DtDdWrapper'); $this->addElements(array($firstName, $lastName, $emailAddress, $password, $confirmPassword, $rastaurantname, $description, $phone, $source, $sourcedescription, $website, $dateofbirth, $register, $reset, $captcha, $comapnyid, $countryCode, $resownercity, $resownerzipcode)); }
/** * Строит форму * * @param array $fields Массив данных о полях формы * * @return Zend_Form */ public function buildForm($fields) { $form = Phorm_Form::makeForm(); foreach ($fields as $data) { $fieldname = "field_" . $data["fieldid"]; switch ($data["fieldtype"]) { /** * Однострочное текстовое поле */ case "Text": $field = new Zend_Form_Element_Text($fieldname); // Типы валидаторов if ($data["fieldvalidators"] == "Email") { $field->addValidator("EmailAddress", true, array("messages" => array("emailAddressInvalid" => $this->_translate->_("Неверно указан email"), "emailAddressInvalidHostname" => $this->_translate->_("Неверно указан email"), "emailAddressInvalidMxRecord" => $this->_translate->_("Неверно указан email"), "emailAddressInvalidSegment" => $this->_translate->_("Неверно указан email"), "emailAddressDotAtom" => $this->_translate->_("Неверно указан email"), "emailAddressQuotedString" => $this->_translate->_("Неверно указан email"), "emailAddressInvalidLocalPart" => $this->_translate->_("Неверно указан email"), "emailAddressLengthExceeded" => $this->_translate->_("Неверно указан email"), "emailAddressInvalidFormat" => $this->_translate->_("Неверный формат")))); } elseif ($data["fieldvalidators"] == "Date") { $field->addValidator("Date", true, array("messages" => array("dateInvalid" => $this->_translate->_("Неверная дата"), "dateInvalidDate" => $this->_translate->_("Неверная дата"), "dateFalseFormat" => $this->_translate->_("Неверная дата")))); } elseif ($data["fieldvalidators"] == "Int") { $field->addValidator("Int", true, array("messages" => array("notInt" => $this->_translate->_("Значение должно быть числом"), "intInvalid" => $this->_translate->_("Значение должно быть числом")))); } elseif ($data["fieldvalidators"] == "Hostname") { $field->addValidator("Hostname", true, array("messages" => array("hostnameInvalid" => $this->_translate->_("Неверный адрес"), "hostnameIpAddressNotAllowed" => $this->_translate->_("Неверный адрес"), "hostnameUnknownTld" => $this->_translate->_("Неверный адрес"), "hostnameDashCharacter" => $this->_translate->_("Неверный адрес"), "hostnameInvalidHostnameSchema" => $this->_translate->_("Неверный адрес"), "hostnameUndecipherableTld" => $this->_translate->_("Неверный адрес"), "hostnameInvalidHostname" => $this->_translate->_("Неверный адрес"), "hostnameInvalidLocalName" => $this->_translate->_("Неверный адрес"), "hostnameLocalNameNotAllowed" => $this->_translate->_("Неверный адрес"), "hostnameCannotDecodePunycode" => $this->_translate->_("Неверный адрес")))); } // Если разрешен HTML if ($data["htmlallowed"] == "yes") { $field->addFilter("StringTrim"); } else { $field->addFilter("StripTags"); } break; /** * Многострочное текстовое поле */ /** * Многострочное текстовое поле */ case "Textarea": $field = new Zend_Form_Element_Textarea($fieldname); // Если разрешен HTML if ($data["htmlallowed"] == "yes") { $field->addFilter("StringTrim"); } else { $field->addFilter("StripTags"); } break; /** * Чекбокс */ /** * Чекбокс */ case "Checkbox": $field = new Zend_Form_Element_Checkbox($fieldname); break; /** * Радиоточка */ /** * Радиоточка */ case "Radio": $field = new Zend_Form_Element_Radio($fieldname); break; /** * Список */ /** * Список */ case "Select": $field = new Zend_Form_Element_Select($fieldname); $haystack = array(); $optionsdata = explode("\n", $data["optionsdata"]); foreach ($optionsdata as $k => $v) { $haystack[$k] = trim($v); } $field->addMultiOption("", $this->_translate->_("---Выберите---")); foreach ($haystack as $value) { $field->addMultiOption($value, $value); } $haystack[$this->_translate->_("---Выберите---")] = ""; $field->addValidator("InArray", true, array("haystack" => $haystack, "messages" => array("notInArray" => $this->_translate->_("Не выбрано ни одного значения")))); break; /** * Список с множественным выбором */ /** * Список с множественным выбором */ case "Multiselect": $field = new Zend_Form_Element_Multiselect($fieldname); $haystack = array(); $optionsdata = explode("\n", $data["optionsdata"]); foreach ($optionsdata as $k => $v) { $haystack[$k] = trim($v); } foreach ($optionsdata as $value) { $field->addMultiOption($value, $value); } $field->addValidator("InArray", true, array("haystack" => $haystack, "messages" => array("notInArray" => $this->_translate->_("Не выбрано ни одного значения")))); break; /** * Файл */ /** * Файл */ case "File": $field = new Zend_Form_Element_File($fieldname); if ($data["filestypes"] == "Images") { $field->addValidator("Extension", false, array("extension" => "png,jpg,gif,jpeg,bmp", "messages" => array("fileExtensionFalse" => $this->_translate->_("Файл '%value%' не является изображением")))); } elseif ($data["filestypes"] == "Documents") { $field->addValidator("Extension", false, array("extension" => "doc,xls,odt,docx,xlsx,pdf,txt", "messages" => array("fileExtensionFalse" => $this->_translate->_("Файл '%value%' не является документом")))); } elseif ($data["filestypes"] == "Archives") { $field->addValidator("Extension", false, array("extension" => "zip,rar,7z,gz,tgz", "messages" => array("fileExtensionFalse" => $this->_translate->_("Файл '%value%' не является файловым архивом")))); } //$field -> setDestination($this->paths["html"]."forms/files/"); $field->setValueDisabled(true); break; /** * Refferer */ /** * Refferer */ case "Refferer": $field = new Zend_Form_Element_Hidden($fieldname); if (isset($_SERVER["HTTP_REFERER"])) { $field->setValue($_SERVER["HTTP_REFERER"]); } break; /** * CAPTCHA */ /** * CAPTCHA */ case "Captcha": $captcha = Phorm_Captcha_Image::getCaptcha(); $captcha->setOptions(array("messages" => array("badCaptcha" => $this->_translate->_("Неверно указан код подтверждения"), "missingID" => $this->_translate->_("Неверный идентификатор Captcha")))); $field = new Zend_Form_Element_Captcha($fieldname, array("captcha" => $captcha)); break; default: continue; } // Если поле обязательно для заполнения if ($data["isrequired"] == "yes") { $field->setRequired(true)->addValidator("NotEmpty", true, array("messages" => array("isEmpty" => $this->_translate->_("Не заполнено поле")))); } // Устанавливаем заголовок и описание поля if ($field instanceof Zend_Form_Element_Hidden) { $field->removeDecorator("label")->removeDecorator("HtmlTag"); } else { $field->setLabel($data["fieldname"])->setDescription($data["fieldtxt"]); } $form->addElement($field); } $form->addElement(new Zend_Form_Element_Submit("Send", $this->_translate->_("Отправить"))); $form->setAttrib('enctype', 'multipart/form-data'); return $form; }
function setForm() { $form = new Zend_Form; $form->setMethod('post')->setAction(''); $comment_name = new Zend_Form_Element_Text('comment_name'); $comment_name->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Vui lòng nhập tên người gửi !')); $comment_name->setAttrib('class','n'); $comment_name->setAttrib("onfocus","if (this.value == 'Nhập tên của bạn') {this.value = '';}"); $comment_name->setAttrib("onblur","if (this.value == '') {this.value = 'Nhập tên của bạn';}"); $comment_name->setValue("Nhập tên của bạn"); $comment_email = new Zend_Form_Element_Text('comment_email'); $comment_email->addValidator('EmailAddress',true,array('messages'=>'Địa chỉ email không hợp lệ')); $comment_email->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Vui lòng nhập địa chỉ email !')); $comment_email->setAttrib('class','e'); $comment_email->setAttrib('onfocus',"if (this.value == 'Nhập địa chỉ email của bạn') {this.value = '';}"); $comment_email->setAttrib('onblur',"if (this.value == '') {this.value = 'Nhập địa chỉ email của bạn';}"); $comment_email->setValue('Nhập địa chỉ email của bạn'); $comment_content = new Zend_Form_Element_Textarea('comment_content'); $comment_content->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Vui lòng nhập nội dung bình luận!')); $comment_content->setAttrib('class','m'); $comment_content->setAttrib('onfocus',"if (this.value == 'Nhập nội dung bình luận') {this.value = '';}"); $comment_content->setAttrib('onblur',"if (this.value == '') {this.value = 'Nhập nội dung bình luận';}"); $comment_content->setValue('Nhập nội dung bình luận'); $comment_captcha = new Zend_Form_Element_Captcha('comment_captcha',array( 'label' => 'Captcha_image', 'captcha' => array( 'captcha' => 'Image', 'wordLen' => 6, 'timeout' => 300, 'font' => APPLICATION_PATH.'/templates/front/fonts/tiennd.TTF', 'imgDir' => APPLICATION_PATH.'/templates/front/captcha/', 'imgUrl' => $this->view->baseUrl().'/application/templates/front/captcha/', 'height' => 100, 'width' => 200, 'fontSize' => 50, ), )); $comment_captcha->setAttrib('class','captcha_image1'); $comment_captcha->setAttrib('onfocus',"if (this.value == 'Nhập hình ảnh xác nhận') {this.value = '';}"); $comment_captcha->setAttrib('onblur',"if (this.value == '') {this.value = 'Nhập hình ảnh xác nhận';}"); $comment_captcha->setValue('Nhập hình ảnh xác nhận'); $comment_name->removeDecorator('HtmlTag')->removeDecorator('Label'); $comment_email->removeDecorator('HtmlTag')->removeDecorator('Label'); $comment_content->removeDecorator('HtmlTag')->removeDecorator('Label'); $comment_captcha->removeDecorator('HtmlTag')->removeDecorator('Label'); $form->addElements(array($comment_name,$comment_email,$comment_content,$comment_captcha)); return $form; }