symfony 1.4 how to get POST parameters?
Asked Answered
M

2

6

I can get a parameter('id' for example) by $request->getParameter('id');

but if I use a form to POST the id, how could I get its value? $request->getParameter('id'); doesn't work.

Milkwort answered 20/8, 2010 at 15:4 Comment(5)
This should work. Are you sure you're posting the data you're looking for?Eschar
Darragh Enright. symfony 1.4 doesn't work. What version are you talking about? getPostParameter() works.Milkwort
Hi. I'm using 1.4 too. By the way, I'm not disputing the use of getPostParameter(). It's perfect. However... This seems like strange behaviour. Assuming that what you're doing is routine enough, parameters contained in the current Request object should be available via the same interface, irrespective of the request method. So, generally speaking, $request->getParameter('my_post_parameter') should, and does, work for retrieving POST parameters. If you see it in documentation it's up-to-date. Just my 2c :)Eschar
Hello Darragh Enright, I tried again, if I use getPostParamter(), everything is good. But if I change it to getParamter(), my program breaks because I get null from the method. Although I feel the same way as you, symfony 1.4 just doesn't permit me to get a post paramter's value through getParameter(). Could you please try again and let me know your result? (please try another parameter other than "id", as we all know that "id" is a special parameter.)Milkwort
I tried it myself (fetching differently named parameters - both from the form object itself and manually created hidden input fields in the form) and I had no problems. maybe have a look at the parameter holder and see what's in there? print_r($request->getParameterHolder());Eschar
W
16

sfWebRequest has getPostParameter(name, default)

Whitford answered 20/8, 2010 at 15:26 Comment(1)
Thank you very much! I searched google a lot but didn't find the answer, seems that most of the information about symfony are out-of-date.Milkwort
I
4

In the Form, the Post Parameter Name is (by default): Model[colum name]

For example:

<input type="text" id="user_email" name="user[email]">

In the Action (after post):

$request->getPostParameter('user[email]');

Note: $request is the type sfWebRequest

Imelda answered 22/6, 2011 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.