Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2012, 07:45 AM   PM User | #1
inzid
New Coder

 
Join Date: Jan 2012
Posts: 25
Thanks: 5
Thanked 0 Times in 0 Posts
inzid is an unknown quantity at this point
html & php

Hi,

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

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

PHP Code:
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;


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.

Last edited by inzid; 01-28-2012 at 07:47 AM..
inzid is offline   Reply With Quote
Old 01-28-2012, 10:12 AM   PM User | #2
KuriosJon
Regular Coder

 
Join Date: Jan 2012
Posts: 134
Thanks: 0
Thanked 32 Times in 32 Posts
KuriosJon is on a distinguished road
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.
KuriosJon is offline   Reply With Quote
Users who have thanked KuriosJon for this post:
inzid (01-28-2012)
Old 01-28-2012, 07:48 PM   PM User | #3
inzid
New Coder

 
Join Date: Jan 2012
Posts: 25
Thanks: 5
Thanked 0 Times in 0 Posts
inzid is an unknown quantity at this point
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)


PHP Code:
<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

Last edited by inzid; 01-28-2012 at 07:51 PM..
inzid is offline   Reply With Quote
Old 01-28-2012, 10:26 PM   PM User | #4
KuriosJon
Regular Coder

 
Join Date: Jan 2012
Posts: 134
Thanks: 0
Thanked 32 Times in 32 Posts
KuriosJon is on a distinguished road
Instead of this:

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

PHP Code:
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.
KuriosJon is offline   Reply With Quote
Users who have thanked KuriosJon for this post:
inzid (01-29-2012)
Old 01-29-2012, 02:12 AM   PM User | #5
inzid
New Coder

 
Join Date: Jan 2012
Posts: 25
Thanks: 5
Thanked 0 Times in 0 Posts
inzid is an unknown quantity at this point
Thank you, I will try this when I get home
inzid is offline   Reply With Quote
Old 01-29-2012, 05:36 AM   PM User | #6
inzid
New Coder

 
Join Date: Jan 2012
Posts: 25
Thanks: 5
Thanked 0 Times in 0 Posts
inzid is an unknown quantity at this point
works ! thanks heaps
inzid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:14 PM.


Advertisement
Log in to turn off these ads.