Pass values collected in button click to php variable

1

I'm a beginner in PHP and I have the following problem:

I have a table, which each line has a title, and three buttons that have values, the user clicks the button 1 or 2 o 3, I need to store some information like title, date, value of button clicked etc.

But it can do this in several lines, that is, several titles, several dates etc.

And when I click Finish, I need to store those values in an array in PHP, could anyone help me?

    
asked by anonymous 30.04.2018 / 03:11

1 answer

0

I do not know if this is what you want, but it might be a start. Note that this example needs a required parameter, which in this case is the value. You can change the checkbox for your button if it is the way I understood it.

acao.php page

<?php
// recebe os valores filtrando linhas com resultados vazios 
@$titulo =array_filter($_POST["titulo"]);
@$data =array_filter($_POST["data"]);
@$valor =array_filter($_POST["valor"]);

//faz o loop para obter os dados do array (Esse exemplo só funciona com o algum valor sendo passado obrigatóriamente no caso o campo valor)
foreach ($valor as $key)  {
    @$SliceValor   = explode(',', $valor[$key]);
     $SliceValor[0]."<br>"; 
     $SliceValor[1]."<br>";
     $SliceValor[2]."<br>";

}

?>

Form Page

<form role="form" action="acao.php" method="POST">
    <?php
    //aqui vc faz o loop da sua query
    while( .... ) :
    ?>

    <!-- // uni todos valores em um array pra cada campo -->
    <input type="checkbox" name="titulo[]" value="<?php echo$titulo ?>"/>
    <input type="checkbox" name="data[]" value="<?php echo$data?>"/>
    <input type="checkbox" name="valor[]" value="<?php echo$valor ?>"/>

    <?php
      //aqui vc faz finaliza loop da sua query
    endwhile :
    ?>


    <div>
        <button type="submit">Finalizar</button>
    </div>

</form>
    
30.04.2018 / 17:10