【问题标题】:does zend form validation require javascript?zend 表单验证是否需要 javascript?
【发布时间】:2011-07-04 10:09:35
【问题描述】:

一个简单的问题 Zend_Form 验证是否需要 javascript?如果它确实发生了如果关闭 JS 会发生什么,它会回退到例如正常的 PHP 验证吗?

抱歉,我在文档中找不到任何内容。

干杯。

编辑:

这是我的表格:

class Application_Form_Test extends Zend_Form {
    public function init() {}
    public function testForm() {
        $email = $this->createElement('text', 'email');
        $email->setLabel('E-Mail Address');
        $email->setRequired(true);
        $email->addFilter('StripTags');
        $email->addErrorMessage('an email address is required');
        $email->addValidator('NotEmpty', true);
        $email->addValidator('EmailAddress');

        $submit = $this->createElement('submit', 'submit', array('label'=>'Submit'));
        $this->addElements(
            array(
                $email, $submit
            )
        );
        return $this;
    }
}

这是我的控制器:

class testController extends Zend_Controller_Action {
    public function init() {
        /* Initialize action controller here */
        if(!Zend_Auth::getInstance()->hasIdentity()) {  
            $this->_redirect('login/index');  
        }
        $this->_acl = new MyAcl(Zend_Auth::getInstance()->getIdentity());               
    }
    public function indexAction() {
        $form = new Application_Form_Test();
        $form = $form->testForm();
        $form->setAction('/dev/public/test/update')->setMethod('post');
        $this->view->form = $form;
    }
    public function updateAction() {
        $form = new Application_Form_Test();
        if($this->getRequest()->isPost()){
            $formData = $this->_request->getPost();
            if($form->isValid($_POST)){
                die('i seem to be valid....');
            }
            else{
                die(var_dump($_POST));
            }
        }   
    }
}

似乎验证失败。有什么想法吗?

【问题讨论】:

    标签: javascript zend-framework zend-form zend-validate


    【解决方案1】:

    不,Zend_Form 验证器(我的意思是验证您使用 addValidator 在表单元素上添加的过滤器,如下所示:

     $element->addValidator ( new Zend_Validate_StringLength ( array ('max' => 5 ) ));
    

    都是服务器端处理的。所以你不必担心javascript。

    如果需要,您可以添加 javascript 验证器客户端以避免返回服务器,但这是另一回事。

    【讨论】:

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