Form in loop in laravel

0

Good morning, I'm trying to make a form in a loop for each row of the table, when the user clicks the button on one row, takes the data from that row and loads it on another page, but for some reason in the loop the inputs do not are inside the form, follow the code of the loop:

if($total_row > 0)
      {
       foreach($data as $row)
       {
        $output .= '
    <tr>
             <form  action="monitor/info" method="POST">
              {{ csrf_field() }}
             <td> <input type="text" readonly="" style="width: 310px"  name="nome" id="nome" value="'.$row->nome.'" /></td>
             <td> <input type="text" readonly="" style="width: 80px" name="usuariox" id="usuariox" value="'.$row->usuario_x.'" /></td>
             <td> <input type="text" readonly="" style="width: 100px" name="aspect" id="aspect" value="'.$row->aspect.'" /></td>
             <td> <input type="text" readonly="" name="supervisor" id="supervisor" value="'.$row->supervisor.'" /></td>
             <td> <input type="text" readonly="" style="width: 70px" name="setor" id="setor" value="'.$row->setor.'" /></td>  
             <td> <input type="submit" class="btn btn-primary" value="Criar Laudo"></td>
             </form>
            </tr>
';
       }
      }
      else
      {
       $output = '
       <tr>
        <td align="center" colspan="5">Nehum registro encontrado!</td>
       </tr>
       ';
      }

Follow the browser as interpreted:

Can anyone tell me where I'm wrong?

    
asked by anonymous 04.12.2018 / 13:27

2 answers

1

If you check the <tr> documentation you will see the following line :

  

Permitted content : Zero or more <td> and / or <th> elements; script-supporting elements ( <script> and <template> ) are also allowed.

That is, in a valid HTML document only elements <th> , <td> , <script> and <template> are allowed inside a <tr> element.

This means that although your string is being "mounted" the way you want, the browser makes changes to the DOM tree by removing or changing invalid code, which is your case.

One solution I would use would be to use <form> in a valid place and use the form of <input> ( compatibility ) to specify which form this <input> belongs.

Example:

<?php

$count = 0;
foreach($data as $row) {
    $count++;
    $output .= <<<HTML
        <tr>
            <td>
                <form id="form-$count" action="monitor/info" method="POST">
                    {{ csrf_field() }}
                    <input name="nome" value="{$row->nome}">
                </form>
            </td>
            <td><input name="usuariox" value="{$row->usuariox}" form="form-$count"></td>
            <td><input name="aspect" value="{$row->aspect}" form="form-$count"></td>
            <td><input name="supervisor" value="{$row->supervisor}" form="form-$count"></td>
            <td><input name="supervisor" value="{$row->supervisor}" form="form-$count"></td>
            <td><input name="setor" value="{$row->setor}" form="form-$count"></td>
            <td><input type="submit" class="btn btn-primary" value="Criar Laudo"></td>
        </tr>
HTML;
}
    
04.12.2018 / 14:12
0

Good afternoon friends, just passing on to inform that I found a simple solution to this problem, I used the javascript session because the object was simple, send information from one page to another, pantry use of call by form, and this does not change the search speed, remains the same,

if($total_row > 0)
      {
       $count = 0;   
       foreach($data as $row)
       {
        $count ++;   
        $output .= '
        <tr>
         <td> <input type="text" readonly="" style="width: 310px"  name="nome'.$count.'" id="nome'.$count.'" value="'.$row->nome.'" /></td>
         <td> <input type="text" readonly="" style="width: 80px" name="usuariox'.$count.'" id="usuariox'.$count.'" value="'.$row->usuario_x.'" /></td>
         <td> <input type="text" readonly="" style="width: 100px" name="aspect'.$count.'" id="aspect'.$count.'" value="'.$row->aspect.'" /></td>
         <td> <input type="text" readonly="" name="supervisor'.$count.'" id="supervisor'.$count.'" value="'.$row->supervisor.'" /></td>
         <td> <input type="text" readonly="" style="width: 70px" name="setor'.$count.'" id="setor'.$count.'" value="'.$row->setor.'" /></td>  
         <td> <button type="button" class="btn btn-primary" id="btn'.$count.'">Criar Laudo</button></td>

         <script>

              $("#btn'.$count.'").click(function(){
                  localStorage.setItem("nome", $("#nome'.$count.'").val());
                  localStorage.setItem("usuariox", $("#usuariox'.$count.'").val());
                  localStorage.setItem("aspect", $("#aspect'.$count.'").val());
                  localStorage.setItem("supervisor", $("#supervisor'.$count.'").val());
                  localStorage.setItem("setor", $("#setor'.$count.'").val());    
                  window.location.href = "http:...endereço da página";
              });

         </script>

        </tr>
        ';
       }
      }
      else
      {
       $output = '
       <tr>
        <td align="center" colspan="5">Nehum registro encontrado!</td>
       </tr>
       ';
      }

and retrieve those sessions on the other page with jquery. abc

    
05.12.2018 / 16:25