Help to pass values from the table inside php via form

Asked

Viewed 735 times

0

Hello friends I need a gallows here next:

I receive a table with the values inside php I need to take the full table and send via the form via post I am not able to send the tebela putting there in the value php

below put first the code I receive the table and just below this the form

<?php
$array_dados = json_decode($_POST["json_dados"]);

$total = 0;

// CABEÇALHO
echo '
  <table width="95%"  border="1" align="center">
    <tr>
      <td width="26%"><div align="center">Nome</div></td>
      <td width="41%"><div align="center">Preco</div></td>
      <td width="33%"><div align="center">Quantidade</div></td>
    <td width="33%"><div align="center">Subtotal</div></td>
    </tr>';

foreach($array_dados as $obj)
{

 echo '
    <tr>
      <td><div align="center">'. $obj->nome . '</div></td>
      <td><div align="center">'. $obj->preco . '</div></td>
      <td><div align="center">'. $obj->qtd . '</div></td>
      <td><div align="center">'. $obj->subtotal . '</div></td>
    </tr>';

    $total = $total + $obj->subtotal;
}

echo '
    <tr><td colspan="4"><div align="center">Total: '.$total.'</div></td></tr>
  </table>';

?>

    <form method="post" action="finaliza.php">
      
   <input type="hidden" name="tabela toda" value="AQUI_A_TABELA">
    
      <input type="submit" value="Finalizar Pedido">
      
    </form>

  • Do you want to send each row of this table all together? Or individual? And where do you want to send it? This way you’re doing it never works.

  • All together what’s inside php I want to put the value there in input !

1 answer

0


Personally I don’t know what you want to do with it, but there’s a solution below. The name of your field hidden is incorrect. There can be no spaces. Have a look.

PHP

<?php
    $array_dados = json_decode($_POST["json_dados"]);

    $total = 0;

    // CABEÇALHO
    $tabela_toda = '
    <table width="95%"  border="1" align="center">
       <tr>
          <td width="26%"><div align="center">Nome</div></td>
          <td width="41%"><div align="center">Preco</div></td>
          <td width="33%"><div align="center">Quantidade</div></td>
          <td width="33%"><div align="center">Subtotal</div></td>
       </tr>';

       foreach($array_dados as $obj)
       {

          $tabela_toda .= '
          <tr>
             <td><div align="center">'. $obj->nome . '</div></td>
             <td><div align="center">'. $obj->preco . '</div></td>
             <td><div align="center">'. $obj->qtd . '</div></td>
             <td><div align="center">'. $obj->subtotal . '</div></td>
          </tr>';

          $total = $total + $obj->subtotal;
       }

       $tabela_toda .= '
       <tr><td colspan="4"><div align="center">Total: '.$total.'</div></td></tr>
    </table>';

    echo $tabela_toda;
?>

HTML

<form method="post" action="finaliza.php">

   <input type="hidden" name="tabela_toda" value="<?=$tabela_toda?>">

   <input type="submit" value="Finalizar Pedido">

</form>
  • Pro more than I put input type="Hidden"it gets displays a piece of table and does not send

  • No type=Hidden. Hidden is declared inside tags.

  • Sends by type=text and uses Hidden within the input field.

  • @Williancok what ? Of course there is. http://www.w3schools.com/TAGs/tryit.asp?filename=tryhtml5_input_type_hidden

  • @Hemersonprestes when you send to PHP do: echo $_POST['tabela_toda']; and see what happens.

Browser other questions tagged

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