PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Deddog
Forum Commoner
Posts: 55 Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton
Post
by Deddog » Fri Nov 29, 2002 9:56 am
Is there a way that the below code can be amended so that if the checkbox is not checked then the varibale gains a value of 0?
<?PHP
printf("<input type=\"checkbox\" name=\"EasyList\" value=\"1\" >");
?>
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Fri Nov 29, 2002 10:25 am
That happens pretty much automatically, as far as I understand it.
Maybe you should only check for values of 1 in your processing code?
PaTTeR
Forum Commoner
Posts: 56 Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:
Post
by PaTTeR » Fri Nov 29, 2002 10:32 am
when checkbox is checked submited value is 'on'
else submited value is not set (don't have $_POST['checkboxname'] )
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Fri Nov 29, 2002 10:50 am
Well, I guess you could do this:
if(!$_POST['variable_name']) {
$variable_name = '0';
}
Basically, if variable_name isn't selected, set it to 0.
You'd have to change those variable_names out to the name of the variables you're using... but it should work.
Deddog
Forum Commoner
Posts: 55 Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton
Post
by Deddog » Fri Nov 29, 2002 11:01 am
Thanks for the replies lads.
I'd already gone for Jim's idea, but it would have been nice to tie it up when i defined the checkbox.
Cheers,
Lee.