Awais Qarni
Awais Qarni

Reputation: 18006

Zend Form Validation not working

I have created a zend form. I have added some elements. I have put validate attribute in all elements but validation in not working out. Here is my code

  /* Form Elements & Other Definitions Here ... */
    $this->setMethod('post');
   $this->addElement('text', 'email', array(
       'required'   => true,
        'filters'    => array('StringTrim'),
        'validators' => array(
            'EmailAddress',
        )
    ));
   // Add the comment element
    $this->addElement('textarea', 'comment', array(
       // 'label'      => 'Please Comment:',
        'required'   => true,
        'validators' => array(
            array('validator' => 'StringLength', 'options' => array(0, 20))
            )
    ));

    // Add a captcha
    $this->addElement('captcha', 'captcha', array(
        //'label'      => 'Please enter the 5 letters displayed below:',
        'required'   => true,
        'captcha'    => array(
            'captcha' => 'Figlet',
            'wordLen' => 5,
            'timeout' => 300
        )
    ));

    // Add the submit button
    $this->addElement('submit', 'submit', array(
       'ignore'   => true,
        'label'    => 'Sign Guestbook',
    ));

    // And finally add some CSRF protection
    $this->addElement('hash', 'csrf', array(
        'ignore' => true,
    ));

Not even a single validation in working out. On my view I just echo the form object. Would any body tell me where Am I Wrong?

Upvotes: 1

Views: 2013

Answers (1)

dinopmi
dinopmi

Reputation: 2673

Zend_Form is supposed to validate your input in the server side. To use it, you need to send the data to the server somehow, and then call $form->isValid($data).

In any case, keep in mind that the validation is always run in the server side.

Hope that helps,

Upvotes: 5

Related Questions