...

View Full Version : Setting Required fields



stfc_boy
07-23-2008, 05:03 PM
Hi All,

Say I have a form with required fields on a website. If one of the fields is not filled in upon submit they values entered in other textboxes keep what is written in them:



<input type="text" name="email" id="email" value="<?php echo $email?>" style="width:200px;" />


But how do you do this with a tickbox?

In my form my tickboxes have a value of yes is indicated, so if they are ticked but a required form field is not filled in how do I keep that ticked value, or can I keep it?



<input type="checkbox" name="the_value" value="Yes">


Thanks

Chris

Fumigator
07-23-2008, 06:27 PM
You just need to add the HTML syntax that defaults a checkbox to checked, which is checked="checked". Throw in an "if" statement to check if the checkbox post/get variable = "Yes" and if it is, add that string to the checkbox tag.

The trick to remember about checkboxes is the get/post variable will not exist at all if the checkbox is not checked. If it's checked, it's there.

stfc_boy
07-23-2008, 06:34 PM
Thanks kinda get it, something like?:



<input type="checkbox" name="basic_exposure" checked="<? if ($the_value == '') echo ' Yes' ?>" value="Yes">


But the form loads as the box ticked automatically?

Fumigator
07-23-2008, 06:39 PM
More like:



<input type="checkbox" name="basic_exposure" <?php if ($basic_exposure == 'Yes') echo "checked='checked'"; ?> value="Yes">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum