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

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

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

java - Cannot secure connection using TLS -