0
This is my Twig form.
<form id="csv" action="{{ path('faturamento_csv') }}" method="post">
{% for elm, value in filtroLocais %}
<input type="hidden" name="{{ elm }}" value="{{ value }}">
{% endfor %}
<button class="btn btn-primary" type="submit">
<i class="icon-bar-chart"></i>
Gerar CSV
</button>
</form>
As a result of the form I have it:
<input type="hidden" value="25" name="0">
<input type="hidden" value="147" name="1">
How do I get these values correctly in Controller? From what I can identify, the form does not send any value with the name "idLocal"
$form = $this->createForm( new LogPesquisaType() );
$form->bind( $request );
$data = $form->getData();
$filtroLocais = array(); // Inicializa array com locais a pesquisar
foreach ( $data['idLocal'] as $locais ) {
array_push( $filtroLocais, $locais->getIdLocal() );
}
$printers = $this->getDoctrine()->getRepository( 'CacicCommonBundle:LogAcesso')
->faturamentoCsv( $data['dtAcaoInicio'], $data['dtAcaoFim'], $filtroLocais);
What’s the problem with your code? Does it give an error? . . You can [Edit] the question to add information.
– brasofilo
no error, but I can’t get these values from the controller
– Bruno Menezes
already gave a var_dump in $_POST to see what comes ? put the result there
– Otto
@Otto has this in the $_POST array(2) { [0]=> string(3) "122" [1]=> string(3) "128" } s]at the exact values I need to pick up :(
– Bruno Menezes
but you’re trying to get the $data['idLocal'] from the array but it doesn’t exist
– Otto
got :) Thanks Otto. using $_POST['0'] I get the value. now just pass it all to an array.. right?
– Bruno Menezes
here $data = $form->getData(); so does $data['idLocal'] = $form->getData(); if I’m not mistaken you already solve your problem remember to score neh
– Otto