Justin
Justin

Reputation: 162

how to get form method type in Zend framework?

i came across to a kind of dilemma when working on my project in Zend Framework. When we submit a form, we get the values like this:

$post = $this->_request->getParams(); 

this will basically capture all the names in a form that is submitted and i can reach the single name value like this:

$key= $post['key']; 

And the confusion comes in here when there is a variable value coming from URL, such as:

http://www.mydomain.com/contoller/key/11

so i was to capture the key value from the url i can get it like this again:

$post = $this->_request->getParams(); 
$key=$post['key'];

My question, how can i differentiate that if this value is coming from URL or from a form? Or If there is a more secure/reliable way to do this, what would it be? Thank you

Upvotes: 0

Views: 1457

Answers (2)

Developer
Developer

Reputation: 26173

Although question is about ZF1 but every time I search in google this question comes up for zf2 as well.

So if you wish to get Post types in ZF2 such as GET, POST, DELETE, PUT

You can use following within controller.

$this->request->getMethod(); //return submit type i.e. GET, POST, DELETE, PUT

or

$this->getRequest()->getMethod(); //return submit type i.e. GET, POST, DELETE, PUT

https://zf2.readthedocs.org/en/release-2.2.0/modules/zend.http.request.html

https://zf2.readthedocs.org/en/latest/modules/zend.http.request.html

Upvotes: 0

Phil
Phil

Reputation: 164752

To isolate POST data, simply use

$postData = $this->getRequest()->getPost();

You can also retrieve a single value using

$key = $this->getRequest()->getPost('key');

See http://framework.zend.com/manual/1.12/en/zend.controller.request.html#zend.controller.request.http.dataacess

Upvotes: 3

Related Questions