mercredi 25 février 2015

how can I submit the value of an unchecked checkbox

I have a user edit page with a set of user permissions. Each permission is basically a checkbox. If checked the user has the permission if unchecked the user does not have the permission. So if I want to remove a permission I would uncheck the box and vice versa to add a permission.


I got everything to work using a hidden input, but the problem that I am having is that it is submitting both the hidden input and the checkbox value. For example even if I don't make a change and click the update button, I get a message that reads:



Removed access from 1 permission levels
Added access to 1 permission levels


I will show you my code below. Something to keep in mind is that each input calls a different function.


Here is the inputs:



<input type="hidden" name="removePermission[<?php echo $v1['id'] ?>]" id="removePermission[<?php echo $v1['id'] ?>]" value="<?php echo $v1['id'] ?>" >
<input type="checkbox" checked data-toggle="switch" name="addPermission[<?php echo $v1['id'] ?>]" id="addPermission[<?php echo $v1['id'] ?>]" value="<?php echo $v1['id'] ?>" >


Even if I add the hidden input underneath the checkbox input I receive the same message. I know it has something to do with using different functions so can anyone guide me in the right direction? Should I use some JS code to find if it is checked or not?





Aucun commentaire:

Enregistrer un commentaire