开发者

does zend form validation require javascript?

A quick question does Zend_Form validation require javascript? If it does what happens if JS is switched off, would it fall back to normal PHP validation for instance.

Sorry for the noob question I just can't find anything in the docs.

Cheers.

EDIT:

This is my form:

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;
    }
}

and this is my controller:

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));
            }
        }   
    }
}开发者_C百科

It seems to be failing validation. Any ideas?


No, Zend_Form validators (i mean validate filters you add with addValidator on form elements like this:

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

are all processed server side. So you don't have to worry about javascript.

You can add javascript validators client side to avoid trips back to the server if you want, but that's another thing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜