开发者

Error message for input validation is not displaying

Iam new to Zend Framework please help me out...

// create text input for pharmacy name
  $name = new Zend_Form_Element_Text('name');
  $name->setOptions(array('size' => '30'))
    ->setRequired(true)
    ->addValidator('NotEmpty')
    ->addValidator('Alpha');
  $name->getValidator('NotEmpty')->setMessage('Please enter pharmacy name.');
        $name->getValidator('Alpha')->setMessage('PharmacyName can only contain letters and spaces.');


  // create submit button
  $submit = new Zend_Fo开发者_如何学Crm_Element_Submit('submit');
  $submit->removeDecorator('HtmlTag');
  $submit->setLabel('Save')
  ->setOptions(array('class' => 'submit'));

  // attach elements to form
  $this->addElement($cd)
   ->addElement($name)
   ->addElement($submit);


I use a construct as the following to define element parameters:

$this->addElement('text', 'o_title', array(
        'label'      => 'title....',
        'required'   => true,
        'filters'    => array('StringTrim','WordLength'),
        'validators' => array(
            array('validator' => 'StringLength', 'options' => array(0, 40,'utf8',   
                                  'messages'=>array('stringLengthTooLong'=>'Text too long'))),
                   array('NotEmpty', true,  
                             array('messages'=>array('isEmpty'=>"Field must not be empty")))
            ),
        'maxlength' => 40,
        'decorators' => array('Uniform'),
        'description'=> 'input only 40 chars'
    ));

Validators are specified in two ways in the above code .... Each validator can have many messages ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜