How to retrieve form object , to the controller if i am not using zend_form to generate the forms
I have a form like below in the view :
Here i am not using the zend_form , how can i read the values passed when i am in the controller.
function updateproductsAction(){
//$request = $this->getRequest();
echo "<pre>";
print_r($this->getRequest('POST'));
}
above is the controller. I need t开发者_StackOverflow社区o read the values passed from the input tags.
thanks in advance
Gayan
Assuming your controller is "ProductsController" (you didn't give the name), and assuming your form's action="/products/updateproducts" and method="POST" (your form source code is missing), then:
function updateproductsAction() {
if ($this->_request->isPost()) {
// Assuming input tag "name" values are product_id and quantity:
$productId = $this->_request->getParam('product_id');
$quantity = $this->_request->getParam('quantity');
// etc.. for input tags
}
}
If you were to use Zend_Form (I highly recommend doing so), then the code would be slightly modified as follows:
function updateproductsAction() {
$form = new My_Form_UpdateProducts();
if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
$productId = $this->_request->getParam('product_id');
// etc..
}
}
Using Zend_Form allows you to do input validation and filtering and such with minimal effort (i.e. trimming spaces, making all lower/uppercase, ensuring only numeric values were input, etc).
If you were to use method="GET", then isPost() becomes isGet() and getPost() becomes getQuery().
精彩评论