Pass collected values at the click of the button to php variable

Asked

Viewed 533 times

1

I am a beginner in PHP and I have the following problem:

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

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

And when I click finish, I need to store these values in an array in PHP, someone could help me ?

  • If possible use the Stack Overflow tool itself to draw the page so we can understand your question.

  • Show what you’ve got and what you’ve tried

1 answer

0

I don’t know if this is what you want but it can be a start. Note that this example needs a mandatory parameter which in this case is the value. You can switch the checkbox to your button if that’s the way I understand it.

Page acao.php

<?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>

Browser other questions tagged

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