Pick up form value

Asked

Viewed 536 times

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.

  • no error, but I can’t get these values from the controller

  • already gave a var_dump in $_POST to see what comes ? put the result there

  • @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 :(

  • but you’re trying to get the $data['idLocal'] from the array but it doesn’t exist

  • got :) Thanks Otto. using $_POST['0'] I get the value. now just pass it all to an array.. right?

  • here $data = $form->getData(); so does $data['idLocal'] = $form->getData(); if I’m not mistaken you already solve your problem remember to score neh

Show 2 more comments

1 answer

0


but you’re trying to catch the $data['idLocal'] of the array but does not exist

here $data = $form->getData(); do so $data['idLocal'] = $form->getData(); If I’m not mistaken I’ve solved your problem

  • not completely resolve pq generates an error: PHP Fatal error: Call to a Member Function getIdLocal() on a non-object. But there is another problem. Thank you!

  • getIdLocal means that you are seeking an object .... we are passing an array of the post to a variable only ... remains an array. Give a positive ai

Browser other questions tagged

You are not signed in. Login or sign up in order to post.