Recover all checked checkboxes

Asked

Viewed 51 times

2

I have this code that returns a list of the bank with a checkbox next to each, however when sending it via post only takes the last marked and not all:

Example with vardump where I marked all:

array(2) { ["seriais"]=> string(10) "3040156800" ["enviar"]=> string(9) "Solicitar" }

only that I want to recover all checkboxs marked, and only returns the last.

FORM:

<form method="post" action="teste.php" id="ajax_form">
<table align="left">
<tr>        
<?

  $query_tpex = mysqli_query($con,"SELECT a.* , b.* , c.*,d.* , e.* FROM controle_contratos a, reparaveis b, projetos c, contratos d, empresa e WHERE a.status = 'Recebida' and a.id_contrato = '$numero_contrato' and a.id_pn = '$id_pn' and a.data_coleta <> '0000-00-00' and a.id_pn = b.id_pn and a.id_projeto = c.id_projeto and a.id_contrato = d.id_contrato and d.id_empresa = e.id_empresa");

  while($linha = mysqli_fetch_array($query_tpex)){

  ?>
    <br>
 <input type="checkbox" class='marcar' name="seriais"  value="<?=$linha['ordem_servico']; ?>" />

  <? echo "O.S:"." ".$linha['ordem_servico']."-------- Serial: ".$linha['sn']; ?></label>

  <? } ?>
  </tr>

  <tr><br>
  </button><button id='todos' type="button" onclick='marcardesmarcar();'>Marcar/Desmarcar</button>
    <br>    <label><input type="submit" class="but but-success" name="enviar" value="Solicitar" /></label>

    </form>

1 answer

2


Put clasps on name of input:

<input type="checkbox" class='marcar' name="seriais[]"  value="<?=$linha['ordem_servico']; ?>" />

This way it will send an array with all the selected values, which you can take on PHP with:

$seriais = $_POST['seriais'];
  • Thanks my friend! That’s right! Hug!

Browser other questions tagged

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