-
check box values with php
i got this on line form and I use PHP as the backend. all the text boxes and drop down list values get sent but how to I work it so that a radio button or check box values gets sent?
thanks
-
Hi
I'm currently working on email forms in Flash and have managed to get the information from basic text fields sent to my email using PHP...
I noticed you have managed to sort combo boxes out, so the info come back to you...
Any chance of some help, its been driving me mad now for about a week...
Cheers
-
Dramaphree
did you ever figure out teh check box issue? I'm trying to figure that out myself... Send me some help if you can.
Thanks
Mike C
-
associate
Check Boxes:
An unchecked checkbox will Submit nothing to the php script....
So to see if a checkbox was check you would do something like this
PHP Code:
if(isset($_REQUEST['mycheckbox'])){
// mycheckbox was checked, so lets put the value in a variable
$myvariable = $_REQUEST['mycheckbox'];
}
A radio button is different.
A submitted radio button will contain the value of the selected button...
PHP Code:
$myvalue = $_REQUEST['myradiogroup'];
-
So, you would basicly set your box up like this:
PHP Code:
<input type="checkbox" name="live_switch" value="y" <? if($live == 'y'){ ?>checked<? } ?>/>
The checked portion is if you happen to get the value from your database and set it. This does not work with Safari for some reason. I have to use "Yes", "No" Drop down boxes for Safari users. If you don't use data from a database, just use...
<input type="checkbox" name="live_switch" value="y" />
Then, when you are processing...
PHP Code:
<?
if($_POST['live_switch'] == 'y'){
$checked = 'yes';
} else {
$checked = 'no';
}
?>
-
associate
Your check-box setup looks ok, but you need to check for the variable beforehand.... see if the post variable is even sent with isset($_REQUEST['live_switch']);
So to complete your first code I would write
PHP Code:
if(isset($_REQUEST['live_switch'])){
/* the box is checked so it must be set
to the only value it is allowed,
which in this case would be y */
$live = 'y';
}
<input type="checkbox" name="live_switch" value="y" <?php if($live == 'y') echo "checked" ?> />
The second part, again, check that the checkbox was selected and sent with isset.
PHP Code:
if(isset($_REQUEST['live_switch'])){
// the checkbox was sent, it must be selected
$checked = true;
}else{
// the check box wasn't checked... nothing was sent.
$checked = false;
}
?>
Last edited by admedia; 10-05-2006 at 08:41 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|