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.

Peter Long
  • 3,964
  • 2
  • 22
  • 18
  • This should work. Are you sure you're posting the data you're looking for? – Darragh Enright Aug 20 '10 at 15:38
  • Darragh Enright. symfony 1.4 doesn't work. What version are you talking about? getPostParameter() works. – Peter Long Aug 20 '10 at 16:09
  • 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 :) – Darragh Enright Aug 20 '10 at 18:47
  • 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.) – Peter Long Aug 21 '10 at 08:22
  • 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()); – Darragh Enright Aug 21 '10 at 17:51

2 Answers2

16

sfWebRequest has getPostParameter(name, default)

Raoul Duke
  • 4,241
  • 2
  • 23
  • 18
  • 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. – Peter Long Aug 20 '10 at 16:08
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

Greg
  • 23,155
  • 11
  • 57
  • 79
Fernando
  • 1,126
  • 12
  • 13