Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: html & php

  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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 08:47 AM.

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    134
    Thanks
    0
    Thanked 32 Times in 32 Posts
    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.

  • Users who have thanked KuriosJon for this post:

    inzid (01-28-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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 08:51 PM.

  • #4
    Regular Coder
    Join Date
    Jan 2012
    Posts
    134
    Thanks
    0
    Thanked 32 Times in 32 Posts
    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.

  • Users who have thanked KuriosJon for this post:

    inzid (01-29-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thank you, I will try this when I get home

  • #6
    New Coder
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts
    works ! thanks heaps


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •