Awais Qarni
Awais Qarni

Reputation: 18016

Adding non empty validation in zend form

I have a misunderstanding about zend non empty validation. I am using following code for zend form to generate a textarea

 $this->addElement('textarea', 'comment', array(
       // 'label'      => 'Please Comment:',
        'required'   => false,
        'validators' => array('NotEmpty')
    ));

If I change required attribute to false then It works and values are not gone to database. But Problem is that if I set requried=>true, It shows the validation message even before submit of form soemthing like this Value is required and can't be empty. Now What I want that this message shouldn't be shown before the form is submitted but validation of non empty should be implemented. Please guide where Am I wrong?

Upvotes: 1

Views: 2436

Answers (1)

JellyBelly
JellyBelly

Reputation: 2431

if you set 'required' => true Zend_Form append in automatic the validator NotEmpty to input textarea. The error messages are displayed only if you execute the method of the isValid() Form. Then calls the isValid the point that you feel most appropriate.

Upvotes: 3

Related Questions