forms - PHP - Checkbox issues when trying to get their values -
so made simple example try , explain me problem can't understand.
the scenario this, have 5 checkboxes in 1 form , button in form. know have created button in same form checkboxes, sake of example, let's absolutely have in different forms. here code:
<?php if(isset($_post['submit2'])){ if(isset($_post['selecao'])){ print_r($_post['selecao']); } } $names = array("joão", "ana", "alex", "carla", "carolina"); ?> <form action="" method="post"> <?php $limite = 5; for($i=0 ; $i<$limite ; $i++){ ?><input type="checkbox" name="selecao[]" value="<?php echo $names[$i]?>"/> <?php } ?> </form> <form action="" method="post"> <input type="submit" name="submit2" value="submit"> </form>
with code this, "print_r($_post['selecao'])" won't executed, however, if have button created in same form checkboxes print_r show array correctly.
my question is, how can work using different forms, possible? in advance replies :)
you have double <form>
tags, , submit or button or checkboxes. if want them submit together, should begin <form>
before checkboxes, , end </form>
after submit, like:
<?php if(isset($_post['submit2'])){ if(isset($_post['selecao'])){ print_r($_post['selecao']); } } $names = array("joão", "ana", "alex", "carla", "carolina"); ?> <form action="" method="post"> <?php $limite = 5; for($i=0 ; $i<$limite ; $i++){ ?><input type="checkbox" name="selecao[]" value="<?php echo $names[$i]?>"/> <?php } ?> <input type="submit" name="submit2" value="submit"> </form>
Comments
Post a Comment