當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Zend_Validate_StringLength::setMessages方法代碼示例

本文整理匯總了PHP中Zend_Validate_StringLength::setMessages方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Validate_StringLength::setMessages方法的具體用法?PHP Zend_Validate_StringLength::setMessages怎麽用?PHP Zend_Validate_StringLength::setMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend_Validate_StringLength的用法示例。


在下文中一共展示了Zend_Validate_StringLength::setMessages方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: init

 /**
  * (non-PHPdoc)
  * @see Zend_Form::init()
  */
 public function init()
 {
     #$this->_addClassNames('well');
     $this->setMethod(Zend_Form::METHOD_POST);
     $this->setTranslator();
     $this->setAttrib('id', 'frmlogin');
     $txtEmail = $this->createElement('text', 'email')->setLabel("ACL_EMAIL")->setRequired(TRUE)->setAttrib('placeholder', 'user@example.com')->addFilters(array(new Zend_Filter_StringToLower(), new Zend_Filter_StringTrim()))->addValidator(new Zend_Validate_EmailAddress());
     #$txtEmail->setDescription('Complete the email');
     $this->addElement($txtEmail);
     $txtPassword = $this->createElement('password', 'password')->setLabel("ACL_PASSWORD")->setRequired(TRUE)->setAttrib('placeholder', '*******');
     #->setAttrib('size', 40);
     $length = new Zend_Validate_StringLength(6, 50);
     $length->setMessages(array('stringLengthTooShort' => sprintf($this->getTranslator()->translate('VALIDATE_PASSWORD_MIN'), 6), 'stringLengthTooLong' => sprintf($this->getTranslator()->translate('VALIDATE_PASSWORD_MAX'), 50)));
     $txtPassword->addValidator($length);
     $this->addElement($txtPassword);
     #$token = new Zend_Form_Element_Hash('token');
     $token = $this->createElement('hash', 'csrflogintoken');
     $token->setSalt(md5(uniqid(rand(), TRUE)));
     $token->setTimeout(300);
     $token->setDecorators(array('ViewHelper'));
     $this->addElement($token);
     $submitOptions = array('buttonType' => Twitter_Bootstrap_Form_Element_Button::BUTTON_SUCCESS, 'type' => 'submit', 'buttonType' => 'success');
     $btnSubmit = new Twitter_Bootstrap_Form_Element_Button('submit', $submitOptions);
     #$btnSubmit = $this->createElement('submit', 'submit');
     $btnSubmit->setLabel('ACL_LOGIN');
     $btnSubmit->removeDecorator('Label');
     $btnSubmit->setDecorators(array(array('FieldSize'), array('ViewHelper'), array('Addon'), array('ElementErrors'), array('Description', array('tag' => 'p', 'class' => 'help-block')), array('HtmlTag', array('tag' => 'div', 'class' => 'controls')), array('Wrapper')));
     $btnSubmit->removeDecorator('Label');
     $this->addElement($btnSubmit);
 }
開發者ID:rogercastaneda,項目名稱:owlsys,代碼行數:34,代碼來源:Login.php

示例2: testSetMessages

 /**
  * Ensures that we can set more than one message at a time,
  * by passing an array of key/message pairs.  Both messages
  * should be defined.
  *
  * @return void
  */
 public function testSetMessages()
 {
     $this->_validator->setMessages(array(Zend_Validate_StringLength::TOO_LONG => 'Your value is too long', Zend_Validate_StringLength::TOO_SHORT => 'Your value is too short'));
     $this->assertFalse($this->_validator->isValid('abcdefghij'));
     $messages = $this->_validator->getMessages();
     $this->assertEquals('Your value is too long', current($messages));
     $this->assertFalse($this->_validator->isValid('abc'));
     $messages = $this->_validator->getMessages();
     $this->assertEquals('Your value is too short', current($messages));
 }
開發者ID:omusico,項目名稱:logica,代碼行數:17,代碼來源:MessageTest.php

示例3: init

 public function init()
 {
     $this->setMethod('post');
     $this->setAttribs(array('id' => 'login_form', 'class' => 'login_form'));
     // Username
     $label = 'Username';
     $validators = array();
     $validator = new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING);
     $validator->setMessages(array(Zend_Validate_NotEmpty::IS_EMPTY => "{$label} is required and must not be empty"));
     $validators[] = $validator;
     $min = 4;
     $max = 20;
     $validator = new Zend_Validate_StringLength(array('min' => $min, 'max' => $max));
     $validator->setMessages(array(Zend_Validate_StringLength::INVALID => "{$label} contains invalid type data", Zend_Validate_StringLength::TOO_SHORT => "{$label} must be at least {$min} characters", Zend_Validate_StringLength::TOO_LONG => "{$label} must be less than {$max} characters"));
     $validators[] = $validator;
     $element = new Zend_Form_Element_Text('username', array('required' => true, 'label' => "{$label}", 'filters' => array(new Zend_Filter_StringTrim()), 'validators' => $validators));
     $this->addElement($element);
     // Password
     $label = 'Password';
     $validators = array();
     $validator = new Zend_Validate_NotEmpty();
     $validator->setMessages(array(Zend_Validate_NotEmpty::IS_EMPTY => "{$label} is required and must not be empty"));
     $validators[] = $validator;
     $min = 4;
     $max = 20;
     $validator = new Zend_Validate_StringLength(array('min' => $min, 'max' => $max));
     $validator->setMessages(array(Zend_Validate_StringLength::INVALID => "{$label} contains invalid type data", Zend_Validate_StringLength::TOO_SHORT => "{$label} must be at least {$min} characters", Zend_Validate_StringLength::TOO_LONG => "{$label} must be less than {$max} characters"));
     $validators[] = $validator;
     $element = new Zend_Form_Element_Password('password', array('required' => true, 'label' => "{$label}", 'filters' => array(new Zend_Filter_StringTrim()), 'validators' => $validators));
     $this->addElement($element);
     // Submit Button
     $label = 'Login';
     $element = new Zend_Form_Element_Submit('submit_button', array('label' => "{$label}", 'ignore' => true, 'class' => 'proxy'));
     $decorators = array('ViewHelper', 'Errors');
     //$element->setDecorators($decorators);
     $this->addElement($element);
     // Hash
     //$element = new Zend_Form_Element_Hash('csrf_hash', array(
     //    'ignore' => true,
     //));
     //$decorators = array(
     //    'ViewHelper',
     //    array(array('input_wrapper' => 'HtmlTag'), array('tag' => 'div', 'style' => 'display: none;')),
     //);
     //$element->setDecorators($decorators);
     //$this->addElement($element);
 }
開發者ID:rocksolidwebdesign,項目名稱:AweCMS,代碼行數:47,代碼來源:Login.php

示例4: validate

 function validate($txtInput)
 {
     $return_array = array();
     $validator = new Zend_Validate_StringLength(3, 250);
     //Validator messages
     $validator->setMessages(array(Zend_Validate_StringLength::TOO_SHORT => 'The string value, \' %value% \' is too short', Zend_Validate_StringLength::TOO_LONG => 'You entered \' %max% \' characters, which is over 250.'));
     // Looping through the text inputs
     foreach ($txtInput as $key => $txtIn) {
         if (!$validator->isValid($txtIn)) {
             $error = $validator->getMessages();
             foreach ($error as $e) {
                 $errorMessage = $key . ': ' . $e;
             }
             array_push($return_array, $errorMessage);
         }
     }
     return $return_array;
 }
開發者ID:jessicatsuji,項目名稱:Portfolio_v1,代碼行數:18,代碼來源:ProjectsModel.php

示例5: _getValidatorStringLength

 /**
  * 
  * @param type $min
  * @param type $max
  * @param type $encoding
  * @param type $messages_prefixed
  * @return Zend_Validate_StringLength 
  */
 protected function _getValidatorStringLength($min = 0, $max = 255, $encoding = 'UTF-8', $messages_prefixed = "")
 {
     $messages_prefixed = strtoupper($messages_prefixed);
     $stringLength = new Zend_Validate_StringLength(array('min' => $min, 'max' => $max, 'encoding' => $encoding));
     $stringLength->setMessages(array(Zend_Validate_StringLength::INVALID => sprintf($this->_translate('ERROR_STRING_LENGTH_INVALID'), $this->_translate($messages_prefixed), $min, $max), Zend_Validate_StringLength::TOO_LONG => sprintf($this->_translate('ERROR_STRING_LENGTH_TOO_LONG'), $this->_translate($messages_prefixed), $max), Zend_Validate_StringLength::TOO_SHORT => sprintf($this->_translate('ERROR_STRING_LENGTH_TOO_SHORT'), $this->_translate($messages_prefixed), $min)));
     return $stringLength;
 }
開發者ID:BGCX067,項目名稱:facebook-store-svn-to-git,代碼行數:15,代碼來源:Form.php

示例6: init

 public function init()
 {
     //$this->setAction('user/process');
     /*
             $decoradores = array(
                                   'ViewHelper',
                                   array('Errors', array('tag' => 'div', 'style' => 'color:red;')),
                                   array('HtmlTag', array('tag' => 'div', 'class' => 'formElement')),
                                   array('Label', array('tag' => 'div'))
                                 );
     
     
             
             // Case 1
             $nombre = new Zend_Form_Element_Text('nombre');
             
             $nombre->setLabel('Nombre :')
                     ->setDecorators($decoradores)
                     ->setRequired(true)
                     ->addFilter('StripTags')
                     ->addFilter('StringTrim')
                     ->addValidator('NotEmpty'); 
     
             $submit = new Zend_Form_Element_Submit( 'Enviar' );
             $submit->setAttrib('id', 'enviar');
     
             
     
             // Case 2
             //StripTags delete las etiquetas HTML
             //StringTrim quita todos los caracteres de espacio en blanco iniciales y finales
             $name = new Zend_Form_Element_Text('name');  
     	
             $name->setLabel('* Your Name:')
                  ->setRequired(true)
                  ->addFilter('StripTags')
                  ->addFilter('StringTrim')
                  ->setAttrib('size',50)
                  ->addValidator('stringLength', false, array(0, 300))
                  ->addValidator('NotEmpty',
                                  true,
                                  array('messages' => array(
                                                             Zend_Validate_NotEmpty::IS_EMPTY => 'Introducir su nombre es obligatorio.'
                                                            )
                                         
                                                         
                                       )
                                 )
                  ->setDecorators($decoradores);
             
             
             // Case 3
             
                 $this->addElement(
                                     'text', 
                                     'userBusinessName', 
                                     array(
                                             'label' => 'Nombre comercial (*)', 
                                             'required' => true, 
                                             'filters' => array('stringTrim'),
                                             'value' => '',
                                             
                                       )
                              );
             
                 $this->userBusinessName->setDecorators($decoradores);
                 //$this->userBusinessName->removeDecorator('Errors');
                 $this->userBusinessName->removeDecorator('HtmlTag');
                 $this->userBusinessName->removeDecorator('Label');
     
             
             
             $this->addElements (array( $nombre, $name, $submit ) );
     */
     // Formulario alta de usuario
     $decoradores = array('ViewHelper', array('Errors', array('tag' => 'div', 'style' => 'color:red;')), 'HtmlTag', 'Label');
     $validatorLenghtClave = new Zend_Validate_StringLength(6, 10);
     $validatorLenghtClave->setMessages(array(Zend_Validate_StringLength::TOO_SHORT => 'La clave es muy corta (min. %min%).', Zend_Validate_StringLength::TOO_LONG => 'La clave es muy large (max. %max%).'));
     $validatorLenghtCP = new Zend_Validate_StringLength(5, 5);
     $validatorLenghtCP->setMessages(array(Zend_Validate_StringLength::TOO_SHORT => 'El CP es de %min% digitos.', Zend_Validate_StringLength::TOO_LONG => 'El CP es de %max% digitos.'));
     // Tipo usuario
     /*
              $this->addElement(  'radio', 
                       'tipo', 
                       array(
                               'value' => '1',
                               'multiOptions' => array(
                                                           
                                                           0 => 'Particular',
                                                           1 => 'Profesional',
                                                      ),
                                           ));
     * 
     */
     // Correo electrónico
     $this->addElement('text', 'correoElectronico', array('label' => '', 'required' => true, 'filters' => array('stringTrim')));
     $this->correoElectronico->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'Introducir su correo electrónico.')));
     $this->correoElectronico->addValidator('EmailAddress', true, array('messages' => array(Zend_Validate_EmailAddress::INVALID => "El tipo especificado no es válido, el valor debe ser una cadena de texto", Zend_Validate_EmailAddress::INVALID_FORMAT => "'%value%' no es una dirección de correo electrónico válida en el formato local-part@hostname", Zend_Validate_EmailAddress::INVALID_HOSTNAME => "'%hostname%' no es un nombre de host válido para la dirección de correo electrónico '%value%'", Zend_Validate_EmailAddress::INVALID_MX_RECORD => "'%hostname%' no parece tener un registro MX válido para la dirección de correo electrónico '%value%'", Zend_Validate_EmailAddress::INVALID_SEGMENT => "'%hostname%' no esta en un segmento de red ruteable. La dirección de correo electrónico '%value%' no se debe poder resolver desde una red pública.", Zend_Validate_EmailAddress::DOT_ATOM => "'%localPart%' no es igual al formato dot-atom", Zend_Validate_EmailAddress::QUOTED_STRING => "'%localPart%' no es igual al formato quoted-string", Zend_Validate_EmailAddress::INVALID_LOCAL_PART => "'%localPart%' no es una parte local válida para la dirección de correo electrónico '%value%'", Zend_Validate_EmailAddress::LENGTH_EXCEEDED => "'%value%' excede la longitud permitida")));
     $this->correoElectronico->setDecorators($decoradores);
     $this->correoElectronico->setAttrib('class', 'form_input_contact');
//.........這裏部分代碼省略.........
開發者ID:eulernunez,項目名稱:RentAFlat-Zend-1,代碼行數:101,代碼來源:UsuarioBack.php

示例7: addPasswordElement

 public function addPasswordElement($isInsert = true)
 {
     require_once 'Zend/Form/Element/Password.php';
     $element = new Zend_Form_Element_Password($this->getPasswordParam());
     $element->clearDecorators()->addDecorator('viewHelper')->setRenderPassword(true);
     #$password = $this->getPermiso()->getRequest()->getPost($this->getPasswordParam());
     $password = isset($_POST[$this->getPasswordParam()]) ? $_POST[$this->getPasswordParam()] : null;
     if ($isInsert || $password) {
         require_once 'Zend/Validate/NotEmpty.php';
         $notEmpty = new Zend_Validate_NotEmpty();
         $notEmpty->setMessages(array(Zend_Validate_NotEmpty::IS_EMPTY => $this->getTranslator()->translate('accountFormHintPasswordNotEmpty')));
         $element->addValidator($notEmpty)->setRequired(true);
         if ($password) {
             require_once 'Zend/Validate/StringLength.php';
             $stringLength = new Zend_Validate_StringLength($this->getPermiso()->getMinimalPasswordLength());
             $stringLength->setMessages(array(Zend_Validate_StringLength::TOO_SHORT => sprintf($this->getTranslator()->translate('accountFormHintPasswordStringLengthTooShort'), $this->getPermiso()->getMinimalPasswordLength())));
             $element->addValidator($stringLength);
         }
     }
     $this->addElement($element);
     return $this;
 }
開發者ID:sitengine,項目名稱:sitengine,代碼行數:22,代碼來源:Form.php


注:本文中的Zend_Validate_StringLength::setMessages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。