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.
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.
Is there no easy way of accessing the posted form data from within the controller?
My HTML Form:
<form id="contact_form" role="form" action="{{ path('submit_query') }}" method="post">`
<div class="panel-body">
<fieldset>
<div class="form-group">
<label for="name" class="control-label">Name</label>
<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">
</div>
<div class="form-group">
<label for="email" class="control-label">Email Address</label>
<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">
</div>
<div class="form-group">
<label for="number" class="control-label">Contact Number</label>
<input type="text" class="form-control" id="number" placeholder="Contact Telephone Number">
</div>
<div class="form-group">
<label for="subject" class="control-label">Subject</label>
<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">
</div>
<div class="form-group">
<label for="query" class="control-label">Query</label>
<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"></textarea>
</div>
</fieldset>
</div>
<div class="panel-footer clearfix text-center"><button type="submit" class="btn btn-default">Submit Query</button></div>
</form>
Controller:
When I try:
public function submitQueryAction(Request $request)
{
$data = $request->request->all();
die(var_dump($data));
}
I get an empty array in "$data".
When I try:
public function submitQueryAction()
{
$data = $this->getRequest()->request->all();
die(var_dump($data));
}
I get a vardump of a Request object, but none of the data is mine. I have also tried the solution presented by Access POST values in Symfony2 request object for getting post values without using an object or entity, but I get an error "Call to undefined method Symfony\Component\Form\Form::bindRequest()".
PLEASE HELP. Thank you in advance.