【问题标题】:zend validator is not workingZend 验证器不工作
【发布时间】:2011-08-10 01:38:56
【问题描述】:

我正在创建 Zend 表单。

当我提交表单时,不会显示错误消息。似乎验证器从未被触发。这是我的代码:

$form = 新 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();

如果($request->isPost())
{
print_r($request->getPost());
}

这是我的装饰器:

公共 $textbox = 数组(

'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')),
);

谁能帮帮我。

【问题讨论】:

  • 我没有看到你调用 isValid ($_POST)。

标签: php zend-framework zend-form zend-decorators


【解决方案1】:

我想你错过了

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

祝你好运:-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多