March 10th, 2013, 03:24 PM
How to tell if an unchecked checkbox is present in invoking form
Because an HTML checkbox sends nothing to the action script if the checkbox is not checked I do not know how to tell whether or not a particular checkbox is actually present in the invoking form. That is I cannot tell the difference between a checkbox that is not present in the input form and one that is not set.
I want to separate the design of the input form from the implementation of the update script. The input form is usually implemented by a different person from the one who is responsible for the update script, because they involve different skill sets. There are 29 flag fields in the database table record that I wish to permit the form designer to update, but I should not have to dictate which specific fields the form designer chooses to update.
What sorts of techniques have been used in the past to deal with this.
March 10th, 2013, 03:58 PM
Simply use the isset() function.
March 10th, 2013, 06:10 PM
You could include a list of the fields in a hidden form field:
<input type="hidden" name="fields" value="checkbox1" />
<input type="hidden" name="fields" value="checkbox2" />
<input type="checkbox name="checkbox1" />
<input type="checkbox name="checkbox2" />
March 10th, 2013, 06:38 PM
Another way to use a hidden field is
isset() to see if it was on the form, empty() or ==0 to see if it was unchecked, !empty() or ==1 to see if it was checked.
<input type="hidden" name="checkbox1" value="0" />
<input type="checkbox" name="checkbox1" value="1" />