Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't figure out how to validate zend_form
    text
    copied!<p>I'm trying to figure out how to get this zend form to validate. I don't understand:</p> <p>Are the addValidator() arguments specific validators? Is there a list somewhere of those validators?</p> <p>I've got this in the forms/contact.php:</p> <p>class Application_Form_Contact extends Zend_Form {</p> <pre><code>public function init() { $this-&gt;setAction('index/process'); $this-&gt;setMethod('post'); $name = new Zend_Form_Element_Text('name'); $name-&gt;setLabel('Name:'); // $name-&gt;addValidator('alnum'); $name-&gt;setRequired(true); $email = new Zend_Form_Element_Text('email'); $email-&gt;setLabel('Email:')-&gt;setRequired(true); $confirm = new Zend_Form_Element_Text('confirm'); $confirm-&gt;setLabel('Confirm Email:')-&gt;setRequired(true); $phone = new Zend_Form_Element_Text('phone'); $phone-&gt;setLabel('Phone:')-&gt;setRequired(true); $subject = new Zend_Form_Element_Select('subject'); $subject-&gt;setLabel('Subject:')-&gt;setRequired(true); $subject-&gt;setMultiOptions(array('Performance'=&gt;'Performance', 'Workshop'=&gt;'Workshop', 'Other'=&gt;'Other' )); $message = new Zend_Form_Element_Textarea('message'); $message-&gt;setLabel('Message:')-&gt;setRequired(true); $message-&gt;setAttrib('rows','6'); $message-&gt;setAttrib('cols','30'); $submit = new Zend_Form_Element_Submit('Submit'); $this-&gt;addElements(array( $name, $email, $confirm, $phone, $subject, $message, $submit )); $this-&gt;setElementDecorators(array ('ViewHelper', array(array('data' =&gt; 'HtmlTag'), array('tag' =&gt; 'td')), array('Label' , array('tag' =&gt; 'td')), array(array('row' =&gt; 'HtmlTag') , array('tag' =&gt; 'tr')) )); $submit-&gt;setDecorators(array('ViewHelper', array(array('data' =&gt; 'HtmlTag'), array('tag' =&gt; 'td')), array(array('emptyrow' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'placement' =&gt; 'PREPEND')), array(array('row' =&gt; 'HtmlTag') , array('tag' =&gt; 'tr')) )); $this-&gt;setDecorators(array( 'FormElements', array('HtmlTag' , array('tag' =&gt; 'table' , 'class' =&gt; 'formTable')), 'Form' ) ); } } </code></pre> <p>my controller is:</p> <pre><code>public function indexAction() { $this-&gt;view-&gt;form = new Application_Form_Contact(); } public function processAction() { // $this-&gt;view-&gt;form = new Application_Form_Contact(); // if ($this-&gt;_request-&gt;isPost()) { $formData = $this-&gt;_request-&gt;getPost(); // echo 'success'; $this-&gt;view-&gt;data = $formdata; } else { // $form-&gt;populate($formData); } } </code></pre> <p>I'm a newbie, so I'm probably making some obvious errors that I don't see. I'm trying to do basic validation:</p> <ul> <li>all fields must be filled out </li> <li>all html gets stripped</li> <li>email and confirm</li> <li>email fields must match </li> <li>email must be valid format.</li> </ul> <p>Any help would be greatly appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload