now we have given the address to the form to where to put the its data. as we click the Submit button the form is posted to the indexAction of the indexController. here is the code to check if the form is submitted or not. if it is submitted than we pass the data to the view index.phtml.
if the form is not submitted than the redirect code will brought us back to the From page.
Make these changes to the indexController.php;
public function indexAction()
{
if (isset($_POST) ) {
$this->view->data = $_POST;
}
else {
$this->redirect('form/index');
}
}
<h1><?php echo $this->data['firstName'];?></h1>
<p><?php echo $this->data['lastName'];?></p>
<h3><?php echo $this->data['email'];?></h3>
now open browser go to localhost/helloworld/public/form/index and add some data to the form. Submit the data and now you will see something like;
if the form is not submitted than the redirect code will brought us back to the From page.
Make these changes to the indexController.php;
public function indexAction()
{
if (isset($_POST) ) {
$this->view->data = $_POST;
}
else {
$this->redirect('form/index');
}
}
and now get the data at the index.phtml like that;
<p><?php echo $this->data['lastName'];?></p>
<h3><?php echo $this->data['email'];?></h3>
now open browser go to localhost/helloworld/public/form/index and add some data to the form. Submit the data and now you will see something like;
No comments:
Post a Comment