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
https://forums.phpfreaks.com/topic/210626-problem-with-html-form-and-check-boxes/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.