Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 - Form method switching from POST to GET?
    primarykey
    data
    text
    <p>I'm building a login form manually in Symfony2 (not using the form builder) and for some reason the POST method is ignored; the target page sees a GET request, so I have no access to the posted field values. </p> <p>Here's the form: </p> <pre><code>&lt;form action="/mysite/web/dologin" method="POST"&gt; Email: &lt;input name=email type=text size=40&gt; Password: &lt;input name=password type=password size=40&gt; &lt;input type=submit&gt; &lt;/form&gt; </code></pre> <p>And the routing.yml entry: </p> <pre><code>dologin: pattern: /dologin/ defaults: { _controller: SiteDefaultBundle:Default:dologin } </code></pre> <p>And the controller action: </p> <pre><code>public function dologinAction() { $request = $this-&gt;getRequest(); var_dump($request); } </code></pre> <p>I submit the form with values in both fields, but no values come through. The relevant section of the resulting request dump looks like this; note no fields in "request": </p> <pre><code> ["request"]=&gt; object(Symfony\Component\HttpFoundation\ParameterBag)#8 (1) { ["parameters":protected]=&gt; array(0) { } } ["query"]=&gt; object(Symfony\Component\HttpFoundation\ParameterBag)#9 (1) { ["parameters":protected]=&gt; array(0) { } } ... ["REQUEST_METHOD"]=&gt; string(3) "GET" </code></pre> <p>If I change the method to "GET" in the HTML form, the request_method recognized is still GET, but the form values are now available: </p> <pre><code> ["request"]=&gt; object(Symfony\Component\HttpFoundation\ParameterBag)#8 (1) { ["parameters":protected]=&gt; array(0) { } } ["query"]=&gt; object(Symfony\Component\HttpFoundation\ParameterBag)#9 (1) { ["parameters":protected]=&gt; array(2) { ["email"]=&gt; string(13) "test@test.com" ["password"]=&gt; string(4) "mypw" } } </code></pre> <p>Why would this be? Why is POST ignored? Is there an encoding type I need to specify? I know you can protect forms in Symfony from cross-site attacks; I'm wondering if that's a default configuration value I need to change. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload