Jump to content

Problem with HTML form and check boxes


leachus2002

Recommended Posts

Hi Everyone,

 

I am having problems when submitting a form that has check boxes within it (post.php). All the check boxes have a name and a checked value of 1 - the receiving page (for example submit.php) has the variables defined:

$tickbox1 = $_POST['tickbox1'];

 

The problem I am finding is that if the box isnt checked - I get an "index is not defined" error. I would suppose because there is no value.

 

I have tried this before and it has worked, however that was on Apache and this is on IIS.

 

Is there a work around?

 

Thanks

Matt

Link to comment
Share on other sites

$tickbox1 = array_key_exists('tickbox1', $_POST) ? 1 : 0;

 

This basically checks to see if the 'tickbox1' key index has been set within the $_POST array. If it has, then set $tickbox1 to 1 (which it would be anyway), otherwise set it to zero if it hasn't been set.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.