1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Rep Power

    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Rep Power
    Simply use the isset() function.

    PHP Code:
    if(isset('subscribe')) {
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Rep Power
    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" />

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    Another way to use a hidden field is
    <input type="hidden" name="checkbox1" value="0" />
    <input type="checkbox" name="checkbox1" value="1" />
    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.

IMN logo majestic logo threadwatch logo seochat tools logo