Help to pass table values that are in php via form

0

Hello friends, I need a strength here:

I get a table with the values inside the php I need to get the whole table and send it via the form via post I can not send the tab by placing there in the value php

Below I put the code that I get the table first and then the form below

<?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>
    
asked by anonymous 05.01.2017 / 06:06

1 answer

0

I do not particularly know what you want to do with this, but there is a solution below. name of your hidden field is incorrect. There can be no spaces. Take 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>
    
05.01.2017 / 11:23