mardi 19 décembre 2017

How to get multiple checked checkbox ID and VALUE at the same time

How to get by POST multiple checked checkbox IDs and VALUEs at the same time? Code bellow shows html to send data.

<form action="" method="post">
  first<input type="checkbox" name="first[]" id="first'<?php echo $data; ?>'" value="first" />
  second<input type="checkbox" name="first[]" id="second'<?php echo $data2; ?>'" value="second" />
  third<input type="checkbox" name="first[]" id="third'<?php echo $data3; ?>'" value="third" />
  <input type="submit" value="submit">
</form>

After send by post I get values, but ID is missing.

foreach($_POST['first'] as $value){
  echo 'VALUE: '.$value.'<br/>';
}

How can I send ID and VALUE and get them by post without explode them? For sure i can split them after, but there should be another way.




Aucun commentaire:

Enregistrer un commentaire