I am developing an application using Symfony2 and twig. I want to submit a value to the controller from a template, this value is set using a Jquery function in the template. I am using a form and a hidden type field for this. This is my controller code:
public function testuaanotatuAction(Request $request)
{
$Interpretatzea = new Interpretatzea();
$Interpretatzea->setMarkagarriaInterpretatua($Markagarria);
$form = $this->createFormBuilder($Interpretatzea)
->add('MarkInterpretazioak', 'hidden')
->getForm();
$Erantzuna = $this->getRequest();
if ($Erantzuna->getMethod() == 'POST')
{
$form->bindRequest($Erantzuna);
if ($form->isValid())
{
return $this->redirect($this->generateUrl('AnotatzaileaAnotatzaileaBundle_FAQ'),
array('proba' => $form->get('MarkInterpretazioak')));
}
}
//Anotatzeko galderaren interfazeari deitu eta azpimarratu beharreko markagarriaren MarkIdent-a pasatu
return $this->render('AnotatzaileaAnotatzaileaBundle:Page:AnotatuInterpretazio.html.twig',
array('form' => $form->createView()));
}
public function FAQAction($proba)
{
return $this->render('AnotatzaileaAnotatzaileaBundle:Page:FAQ.html.twig',array('proba' => $proba));
}
and this is part of the template AnotatuInterpretazio.html.twig where I assign the value to the hidden field using the next JQuery function:
<form action="{{ path('AnotatzaileaAnotatzaileaBundle_testuaanotatu') }}" method="post" {{ form_enctype(form) }} class="erreg">
{{ form_widget(form) }}
<input type="submit" value="Egina" />
</form>
<!-- <a href="{{ path('AnotatzaileaAnotatzaileaBundle_testuaanotatu') }}"><button id="Egina_Botoia">Egina</button></a><br /> -->
<script type='text/javascript'>
$("MatchedTag").click(function ()
{
$(this).toggleClass("highlight");
var Erantzuna = this.id;
$('#hiddenval').val('this.id');//Assigning the value
});
</script>
The browser shows the next error:
The HTTP status code "Array" is not valid.
500 Internal Server Error - InvalidArgumentException
Any idea why can it be?