View Full Version : create variables from checkboxes and radio buttons for sending simple email output

01-16-2004, 08:05 AM
Hello, I've been reading and reading trying to figure out what my best bet is for making checkbox and radio button values into variables and just simply pass them to a php script to email those only with values. The more i read the more I get confused as this seems to be a complex issue when getting into arrays and such.

My Php is very, very beginner level. However, I'm thinking for what I need to do it could be quite simple. I would prefer to stay away from arrays for now until I have time to practice my code and get more advanced with it.

My form is for an on-line job application. The radio buttons and one text field (for other comment) are a list of how the user found out about the position.

The list of checkboxes are for the level of education the user has (therefore they can check more than one)

Then I take these values from the form along with along with some other variables (but these are straight forward text values and file uploads) and pass them to my php script to email them to the recipient.

Where I stumble is:

1) I have a list of 8 radio buttons for choices and 1 text field as an "other" option if their answer isn't a radio button. So on my php script I don't want to send all variable values in email because all but one would have no value. How would I instruct the script to know which one to send?

2) I have a list of checkboxes where any, all or none may be checked. Is there a rookie (very easy) way of sending the checked ones only in the email without getting into arrays? or is there a "beginners" level array function I can understand?

I have named each radiob and ckbx uniquely if this helps

Thank you for any help/suggestions/examples/etc...

01-16-2004, 11:18 AM
<input type="radio" value="yes" name="radiob">
<input type="radio" value="no" name="radiob">
<input type="radio" value="maybe" name="radiob">

<input type="checkbox" value="blue" name="chkbx[]">
<input type="checkbox" value="green" name="chkbx[]">
<input type="checkbox" value="yellow" name="chkbx[]">

note the [] in chkbx[]

... in the receiving script ..

echo 'Selected radiob value = ' . $_POST['radiob'] .'<br />';
echo 'Selected checkbox value(s) = ' . implode( ' , ' , $_POST['chkbx'] );

implode() qives a quick and dirty way of viewing the array contents as a string (here seperated by a comma)

.. alternately you could loop through the 'chkbx' array like so

foreach( $_POST['chkbx'] as $checkbox ){
echo $checkbox .'<br />';

01-16-2004, 05:48 PM
Thank you for simplifiying this fIrepages, it was the [] that had me... I didn't think my case was too complicated but the tutorials and research I did made it very difficult to figure out.

01-19-2004, 03:50 AM
I'm a little stuck on the conditional statement if the user uses the "other" input text box. In other words, if the user's answer is not one of the radio buttons, they can add input into a text field as an option. So where I'm stuck is how to set this conditional statement. Here's what I have and I'm not sure what to put in as a value where the word "checked" is.

if (' . $_POST['radiob'] . ' == "checked" {
$how_find = ' . $_POST['radiob'] . ';

} else {
$how_find = ' . $_POST['hf_other'] . ';

thanks for any help in this matter...

01-19-2004, 03:57 AM
you need to check if the $_POST['radiob'] form value is set/empty

if ( !empty( $_POST['radiob'] ) ) {
$how_find = $_POST['radiob'] ;
} else {
$how_find = $_POST['hf_other'] ;

01-19-2004, 04:45 AM
splendid! thanks mate!!