Log in

View Full Version : php syntax to reset a chkbox?



Jerol
07-09-2006, 07:08 PM
This php code is in my head section:

if(isset($_POST['Submit'])) {$name=$_POST['name']; $email=$_POST['email']; $comments=$_POST['comments']; $mailing=$_POST['mailing'];
then some checks to make sure the user entered data in all the fields.

In the body section, in my form I have this to reload the field after telling the user they didn't fill in completely the form:

<input name="name" type="text" class="text" id="name" value="<?php echo $name; ?>" />

I also need similar php code for a yes/no checkbox but can't figure it out. It needs to do something like:

<input name="mailing" type="checkbox" id="mailing" value="<?php 'true' or 'false' if ($mailing=='true'; ?>" />

Can someone suggest the right syntax?

Thanks,
Jerol

Twey
07-09-2006, 07:37 PM
<?php echo($mailing === 'true' ? 'false' : 'true'); ?>

Jerol
07-09-2006, 07:40 PM
Wow! Thanks, I'll give it a try.