Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the posted data from Form in Zend Framework 2

Im new to Zend Framework, so asking a basic question. I want to get the posted data, in general from one field in a form, I wanted to get the data for debugging purposes.

For example I have a form with fields like username, age and so on. In my controller in addAction(), I want to fetch the username, store it in a variable and use it for debugging purposes. I hope I made it clear. In case if my question is unclear then please do let me know.

Thanks

like image 622
125369 Avatar asked Sep 11 '12 09:09

125369


1 Answers

You're not very clear so I suggets a few solutions...

If you need the plain POST value, you can access it using

$this->getRequest()->getPost('name');

From the controller's context.

If you need the value from the form which has been assigned previously, you can access it using

$form->get('elementName')->getValue();

However, if you're using InputFilters, you need to fetch it using

$form->getInputFilter()->getValue('name');

Otherwise, the value you're retrieving was not passed through the filters.

like image 97
Daniel M Avatar answered Nov 02 '22 10:11

Daniel M