...

View Full Version : html & php



inzid
01-28-2012, 08:45 AM
Hi,

Im trying to link some radio buttons to a html form.

heres the code i got in the html showing the buttons..


Would you like a free phone consultation (15mins)
<br>
<label>
<input type="radio" name="cf_text9" id="YES" value="YES">
YES
</label>
<label>
<input type="radio" name="cf_text10" id="NO" value="NO" >
NO</label>


heres the php code;



$field_message = array($_POST["cf_text0"],$_POST["cf_text1"],$_POST["cf_text2"],$_POST["cf_text3"],$_POST["cf_text4"],$_POST["cf_text5"],$_POST["cf_text6"],$_POST["cf_text7"],$_POST["cf_text8"],$_POST["cf_text9"],$_POST["cf_text10"],$_POST["cf_text11"],$_POST["cf_text12"],$_POST["cf_text13"] );

$mail_to = 'xxxx';
$subject = 'Message from a site visitor '.$field_name;

$field_message="From: {$field_name}
E-mail: {$field_email}

Physical Address: {$field_message[0]}
Postal Address: {$field_message[1]}
Home Phone: {$field_message[2]}
Mobile: {$field_message[3]}
How soon would you like a reply?: {$field_message[4]}
Preferred Contact Method: {$field_message[5]}
Preferred Time of contact 1: {$field_message[7]}
Preferred Time of contact 2: {$field_message[8]}
Would you like a free phone consultation (YES): {$field_message[9]}
Would you like a free phone consultation (NO): {$field_message[10]}



as you can see i have created two different names for the radio button and the current code lets the user select the button and shows up yes or no correctly. but the problem i have is since the radio button name is different they can actually select both buttons..

i hope this makes sense im shocking at explaining things.

here is a link to the website

http://callumpirie.com/dev/form/generalemployee.html


any help would be great.

KuriosJon
01-28-2012, 11:12 AM
Give both radio buttons the same name. Then the user can't select both buttons. When you look at $_POST['radio_button_name'] in PHP, the value will be the value of the selected radio button.

inzid
01-28-2012, 08:48 PM
Yeah i thought i needed the same name. but what part do i edit in the php to make sure when they select yes or no for the Would you like a free phone consultation (15mins) questions. it shows up correctly.

would my html look like this? (NOTE: the name as cf_text9)



<label>
<input type="radio" name="cf_text9" id="YES" value="YES">
YES
</label>
<label>
<input type="radio" name="cf_text9" id="NO" value="NO" >
NO</label>


how would i change my php

KuriosJon
01-28-2012, 11:26 PM
Instead of this:


Would you like a free phone consultation (YES): {$field_message[9]}
Would you like a free phone consultation (NO): {$field_message[10]}

Do this:


Would you like a free phone consultation: {$field_message[9]}

The value of $field_message[9] will be the string "YES" or "NO" since that's the value of those radio buttons.

inzid
01-29-2012, 03:12 AM
Thank you, I will try this when I get home

inzid
01-29-2012, 06:36 AM
works ! thanks heaps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum