Get published data from a form in Zend Framework 2

Im new for Zend Framework, so we ask the main question. I want to get published data, in general, from one field in a form, I wanted to get data for debugging purposes.

For example, I have a form with fields such as username, age, etc. In my controller in addAction () I want to get the username, save it in a variable and use it for debugging purposes. I hope I made it clear. In case my question is unclear, please let me know.

thanks

+7
source share
2 answers

You do not quite understand, so I offer several solutions ...

If you need a simple POST value, you can access it using

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

From the context of the controller.

If you need a value from a form that was previously assigned, you can access it using

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

However, if you use InputFilters, you need to get it with

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

Otherwise, the value you retrieve was not passed through the filters.

+29
source

you can do it like this: in your controller action

 $value = $form->getValue('UserName'); 

this way you can get the value of the zend text field with the identifier 'UserName'

For more information, you can study the code below: Zend Framework Tutorial

0
source

All Articles