开发者

zend validator is not working

I am creating a Zend form.

when i have submit the form then error messages are not showing. It seems that validator is never triggered. This is my code:

$form = new Zend_Form;

  $form->setMethod('POST')
   ->setAttrib('Name','pwdfrm')       
         ->setAttrib('Id','pwdfrm');

     $email = new Zend_Form_Element_Text('email');
  $email->setLabel('Email :')
      ->setDecorators($this->textbox)
      ->setRequired(true)
      ->addValidator('NotEmpty', true)
      ->addErrorMessage('In valid');

          $form->addElements(array($email, 
              new Zend_Form_Element_Submit('submit',array(
                  'decorators' => $this->buttonDecorators,
                  'Label'=>'Submit',
              )),
              ));

  $form->setDecorators(array(   
     'FormElements',
    array('HtmlTag', array('tag' => 'table','align'=>'center','class'=>'tbcss','width'=>'100%','border'=>1)),

'Form',   
     ));

$this->view->assign('form',$form);

$this->_helper->layout->disableLayout();

if($request->isPost())

{

print_r($request->getPost());

}

And this is my decorators:开发者_如何学C

public $textbox = array(

'ViewHelper',     
  'FormElements',   
  array(array('data' => 'HtmlTag'),array('tag' => 'td', 'class' =>

'element','width'=>'43%','valign'=>'top')),

  'Errors',

array(array('closeLabel' => 'HtmlTag'),array('tag' => 'td','closeOnly' => true, 'placement' =>'prepend')),    
     'Label',

array(array('openLabel' =>'HtmlTag'),array('tag' =>'td', >'openOnly'=>true,'align'=>'right','valign'=>'top','width'=>'15%')),

array(array('row' => 'HtmlTag'), array('tag' => 'tr')),   
 );   

public $buttonDecorators = array(

    'ViewHelper',
    'Errors',
  'FormElements',
    array('HtmlTag', array('tag' => 'td','align'=>'center','colspan'=>'2')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);

can anyone help me plz.


I think you missed

 // Check method/data validitiy
   if( !$form->isValid($this->getRequest()->getPost()) ) {
      return;
    }

Good Luck :-)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜