php - Unable to handle unchecked checkbox in loop while save -


i have multiple checkboxes in foreach loop in code

<form method='post' action='save.php'> <?php foreach($problems $problem): ?> <input type='text' name="month[]"/> <input type="checkbox" name="is_increased[]" value="1" /> <?php endforeach; ?> <input type='submit' value='submit'/> </form> 

when save, got values of checked checkboxes only. how checkboxes value, '0' if checkbox unchecked. thank you.

you have this:

<form method='post' action='save.php'> <?php $i = 0; foreach($problems $problem): ?> <input type='text' name=month[<?php echo $i ?>]/> <input type='hidden' name="is_increased[<?php echo $i ?>]" value="0" /> <input type="checkbox" name="is_increased[<?php echo $i ?>]" value="1" /> <?php ++$i; endforeach; ?> <input type='submit' value='submit'/> </form> 

if checkbox checked, value sent server, if not checked, hidden's value sent server


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -