27 Nov
Posted by Ganesh H S , Bangalore, India as zend framework
When i started to develop a web application using zend framework, i couldn’t get much of articles related to how to access form data, zend framework form handling classes are very good approach in handling form, most of them were still under proposal state.
What i really wanted was to access the form data, which i wanted to use for my first module authentication using zend auth, or to insert the form post data in the database during sign up/registration.
To understand how to access <b>zend framework form data</b> prior knowledge of controller and action is required.
Lets consider the URI is: www.webAggregate.com/signup
application/controllers/SignupController.php
<?php
class SignupController extends Zend_Controller_Action
{
function indexAction()
{
if ($this->_request->isPost())
{
echo "Your email address is: " . $this->_request->getPost('email');
}
$this->render("signup");
}
}
application/views/scripts/signup/signup.phtml
<html> <body> <form action="/signup" method="post"> Email: <input name="email" type="text" /> <input name="btnSubmit" value="Click me" type="submit" /> </form> </body> </html>
In the above example index action will be triggered in the signup controller. signup controller extends the zend controller action.
$this->_request->isPost() returns true, if the form is submitted.
$this->_request->getPost(’email’) returns the value of email text field value.
Note:
we can also use $this->_request->getParam(’email’) to get the post value, but its better to use getPost method to acess post form data. Since getParam can also be used to access the get/request method data.
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jul | ||||||
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
RSS feed for comments on this post · TrackBack URI
Leave a reply