Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess HTML form data in Symfony2
    primarykey
    data
    text
    <p>I am new to Symfony. I have seen a lot of threads regarding this topic, but none have been able to answer the question that I have.</p> <p>I have a "Contact" form on my site. This contact form submits to path('submit_query'), which calls the submitQueryController. I am not building the form through Symfony and I am not using an object or entity. My problem is that no matter what I do, I am unable to access the form data within the controller. I have tried every thread suggestion that I have seen, and I either get the REQUEST object with a whole bunch of data (none of which is my form data) or I get nothing.</p> <p>Is there no easy way of accessing the posted form data from within the controller?</p> <p>My HTML Form:</p> <pre><code>&lt;form id="contact_form" role="form" action="{{ path('submit_query') }}" method="post"&gt;` &lt;div class="panel-body"&gt; &lt;fieldset&gt; &lt;div class="form-group"&gt; &lt;label for="name" class="control-label"&gt;Name&lt;/label&gt; &lt;input type="text" class="form-control" id="name" placeholder="Full Name" data-validation-error-msg="Please enter your full name" data-validation="length" data-validation-length="min1"&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="email" class="control-label"&gt;Email Address&lt;/label&gt; &lt;input type="email" class="col-sm-3 form-control" id="email" placeholder="Email Address" data-validation-error-msg="Please enter a valid email address" data-validation="email length" data-validation-length="min1"&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="number" class="control-label"&gt;Contact Number&lt;/label&gt; &lt;input type="text" class="form-control" id="number" placeholder="Contact Telephone Number"&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="subject" class="control-label"&gt;Subject&lt;/label&gt; &lt;input type="text" class="form-control" id="subject" placeholder="The subject of your query" data-validation-error-msg="Please enter a subject for your query" data-validation="length" data-validation-length="min1"&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="query" class="control-label"&gt;Query&lt;/label&gt; &lt;textarea class="form-control" id="query" rows="5" placeholder="Please enter a detailed description of your query" data-validation-error-msg="Please enter your query description" data-validation="length" data-validation-length="min1"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;div class="panel-footer clearfix text-center"&gt;&lt;button type="submit" class="btn btn-default"&gt;Submit Query&lt;/button&gt;&lt;/div&gt; &lt;/form&gt; </code></pre> <p>Controller:</p> <p>When I try:</p> <pre><code>public function submitQueryAction(Request $request) { $data = $request-&gt;request-&gt;all(); die(var_dump($data)); } </code></pre> <p>I get an empty array in "$data".</p> <p>When I try:</p> <pre><code>public function submitQueryAction() { $data = $this-&gt;getRequest()-&gt;request-&gt;all(); die(var_dump($data)); } </code></pre> <p>I get a vardump of a Request object, but none of the data is mine. I have also tried the solution presented by <a href="https://stackoverflow.com/questions/6916324/access-post-values-in-symfony2-request-object">Access POST values in Symfony2 request object</a> for getting post values without using an object or entity, but I get an error "Call to undefined method Symfony\Component\Form\Form::bindRequest()".</p> <p>PLEASE HELP. Thank you in advance.</p>
    singulars
    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.
    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