Click here to Skip to main content
13,091,369 members (55,034 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Problem - don't work form isValid() method.

For begin start Account controller with action 'new', Click 'Submit' and load action success,
and it's don't work, all code below.

But if I put all in one action and form action = same action, ALL WORKS, How can I make the same result using two actions. Sorry for bad Eng.

class AccountController extends Zend_Controller_Action
    public $newAccountForm;
    public function init()
        $this->newAccountForm = new Application_Form_NewAccount();
    public function indexAction()
    public function successAction()
    	if ($this->getRequest()->isPost()) {
    		if ($this->newAccountForm->isValid($this->getRequest()->getPost())) {
	    		//$email 	  = $this->_request->getParam('email');
	    		//$username = $this->_request->getParam('username');
	    		//$password = $this->_request->getParam('password');
	    		//$saveAccount = new Application_Model_SaveAccount();
	    		//$saveAccount->saveAccount($username, $password, $email);
    		} else {
                        // Show form with validation errors
    			$this->view->newAccountForm = $this->newAccountForm;
    public function newAction()
    	$this->view->newAccountForm = $this->newAccountForm;
Posted 23-Apr-13 8:45am
Updated 23-Apr-13 8:55am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

if ($form->isValid($_POST)) {
			$email 	  = $form->getValue("email");
			$username = $form->getValue("username");
			$password = $form->getValue("password");
			//Create Db object
			require_once "Db/Db_Db.php";
			$db = Db_Db::conn();
			//Create the record to save into the Db.
			$userData = array("username" => $username,
					"email" => $email,
					"password" => $password,
					"status" => 'pending',
					"created_date" => new Zend_Db_Expr("NOW()"));
				//Insert into the accounts.
				$db->insert('accounts', $userData);
				//Get the Id of the user
				$userId = $db->lastInsertId();
				//Send out thank you email. We'll get to this. Chapter 6.
			} catch(Zend_Db_Exception $e) {
				$this->view->form = $form;
		} else {
			$this->view->errors = $form->getMessages();
			$this->view->form = $form;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 5 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100