| | |
Validation in Zend Framework Not working in Index Controller
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 17
Reputation:
Solved Threads: 0
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.
here is my index controller
and here is my form page
Kindly make a note to me if anyone can solve this issue
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 Syntax (Toggle Plain Text)
<?php $this->form->setAction($this->url(array('action' => 'index'))); echo $this->form;?>
PHP Syntax (Toggle Plain Text)
<?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"; }
PHP Syntax (Toggle Plain Text)
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
•
•
Join Date: Jul 2008
Posts: 148
Reputation:
Solved Threads: 25
1
#2 27 Days Ago
if you're making the form submit to itself then you need to make the index action in the index controller look for post data so it knows it needs to validate the form.
php Syntax (Toggle Plain Text)
<?php class IndexController extends Zend_Controller_Action { public function indexAction() { $form = new Default_Form_Index(); $request = $this->getRequest(); //Check if we have post data if( $request->isPost() ) { //If the form is NOT valid redisplay it with errors if( !$form->isValid($request->getPost() ) ) { $this->view->form = $form; return; } //Form passes validation and filtering //Do something with the data. $data = $form->getValues(); //Maybe a redirect or change what view is getting rendered? //Just to stop execution after processing the form return; //return; } //If no post data assume we're just displaying the form to the user $this->view->form = $form; } }
If you're question/problem is solved don't forget to mark the thread as Solved!
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
![]() |
Similar Threads
- New to Zend framework (PHP)
- Zend Framework (PHP)
- J2EE Architecture in Brief (JSP)
- Zend Framework: URL issue (IT Professionals' Lounge)
- Zend is making me feel Zendy!! (PHP)
- Choosing Symfony , Zend Framework, CakePHP (PHP)
- Zend framework/MySQL (PHP)
Other Threads in the PHP Forum
- Previous Thread: Function within a loop
- Next Thread: str_replace help needed
| Thread Tools | Search this Thread |
6 action adobe air ajax amf basic button c# cgi check checkbox code copy creat developer directrobot dojofoundation dom eclipse element email files flash flex form forms gdi+ html ibm insert javascript jobs lamp login longisland math open password php post programmer robot rss trouble upload validation validator vb vb6 verify video visual visualbasic visualbasic6 webbrowser website window wpf zend






