Click here to Skip to main content
15,883,731 members
Please Sign up or sign in to vote.
1.00/5 (1 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.

PHP
<?php
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
Updated 23-Apr-13 8:55am
v2

1 solution

PHP
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()"));
				
			try{
				//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;
		}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900