...

View Full Version : Checkboxes n PHP



sarah
04-09-2003, 05:03 PM
Hi Y'all,

How is everyone doing here? Hope your all fine and having better luck with your developing skills than I am - lol!

In my products form I want to ask users if they want to be part of a mailing list - there is a check box for them to tick, how do I pass a value of a checkbox in php?

Sarah

missing-score
04-09-2003, 05:49 PM
If I understand correctly, you dont need php, more just HTML formatting...




Yes! Add me to the list! <input type="radio" name="addtolist" value="yes" checked="checked" />

No, dont add me <input type="radio" name="addtolist" value="no" />



Then the $_GET['addtolist'] variable will be either yes or no, depending on which they checked. You can use this info to decide whether you add them to the list or not.

Íkii
04-10-2003, 12:05 AM
actually - and I'm pretty sure here, checkboxes cannot pass values - they only pass 'on' if they are checked or 'off' if unchecked.

so...

yes: <input type="checkbox" name="a2l[]" />
no: <input type="checkbox" name="a2l[]" />

would send to

$_POST['a2l'][0] = 'on' if yes checked
$_POST['a2l'][1] = 'on' if no checked

as you probably know, naming them the same (whether as an array name or not) means that only one can be checked and all others unchecked.

missing-score
04-10-2003, 07:16 AM
No, they can, because I use a method like this in my forum.

Yes, I do know that only one can be checked, but This is good in this case, as you dont want someone to be able to subscribe and not subscribe at the same time.

Íkii
04-10-2003, 09:28 AM
so you can - sure I couldn't last time I played - odd.

subnote: just found out - it's radio buttons that can be grouped by name so only one can be selected - doesn't appear to work for checkboxes.

thox
04-10-2003, 02:47 PM
<input type="checkbox" name="addtomailinglist" value="on" />


if ($addtomailinglist=='on') {
// code here
}

i can't remember what value it will return if the checkbox is not ticked.

missing-score
04-10-2003, 04:49 PM
I dont think it will return any value.

Be sure to use $_GET['addtomailinglist'] not $addtomailinglist



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum