Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP Zend
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
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 9:45am
Lubomur313
Edited 23-Apr-13 9:55am
v2

1 solution

Rate this: bad
good
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()"));
				
			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;
		}
  Permalink  

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

  Print Answers RSS
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 5 May 2013
Copyright © CodeProject, 1999-2014
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