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.
2 Responses
thamood
May 31st, 2009 at 4:10 am
1thank you very much man i’ll sure keep this in my bookmarks
Michael Stelly
January 31st, 2010 at 12:08 am
2Thanks for the quick excerpt. Information on the getPost() method was exactly what I was looking for.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Blogroll
Recent Comments