Hi All,
I went Through the tutorial of zend framework. . I can able to validate the forms outside the index controller. But the same form which is called in index controller is not validating. I searched in web but none helped me. .
I wanna know why the form is not validating in index controller.
here is my view page.
<?php
$this->form->setAction($this->url(array('action' => 'index')));
echo $this->form;?>
here is my index controller
<?php
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{//echo "login controller";
$form = new Default_Form_Index();
$this->view->form = $form;
// echo "Our home page stuff";
}
and here is my form page
class Default_Form_Index extends Zend_Form
{
/**
* init() is the initialization routine called when Zend_Form objects are
* created. In most cases, it make alot of sense to put definitions in this
* method, as you can see below. This is not required, but suggested.
* There might exist other application scenarios where one might want to
* configure their form objects in a different way, those are best
* described in the manual:
*
* @see http://framework.zend.com/manual/en/zend.form.html
* @return void
*/
public function init()
{
// Set the method for the display form to POST
$this->setMethod('post');
// Add an email element
$this->addElement('text', 'email', array(
'label' => 'Your email address:',
'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,
));
}
}
Kindly make a note to me if anyone can solve this issue