Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Retrieving radio button information in PHP

  1. #1
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Retrieving radio button information in PHP

    I have set up the following form to (a) email confirmation to the user (b) email form input to my address (c) redirect to another page "attendee.html" on submit.

    I had to edit the form to include radio buttons "giss1" and "giss2" and I am having trouble having those results seen in the emails.

    Here's the code:
    Code:
    <?php
    
       
     if(($_POST['college']=="")||($_POST['streetaddress']=="")||($_POST['city']=="")||($_POST['zip']=="")||($_POST['state']=="")||($_POST['contactperson']=="")||($_POST['contactemail']=="")||($_POST['phone']=="")||($_POST['fax']=="")||($_POST['giss1']=="")||($_POST['giss2']==""))
     {
      echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
      if($_POST['college'] == ""){ echo "<li>*College</li>"; }
      if($_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
      if($_POST['city'] == ""){ echo "<li>*City</li>"; }
      if($_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
      if($_POST['state'] == ""){ echo "<li>*State</li>"; }
      if($_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
      if($_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
      if($_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
      echo "</ul><p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p></body></html>";
     }
     
     if(isset($_POST['submit'])) {
    
        $to = "my@email.com"; 
        $subject = "Contact Has Registered";
        $college = $_POST['college'];
        $streetaddress = $_POST['streetaddress'];
        $city = $_POST['city'];
        $state = $_POST['state'];
        $contactperson = $_POST['contactperson'];
        $contactemail = $_POST['contactemail'];
    	$phone = $_POST['phone'];
    if ($selected_radio == 'giss1') {
    $giss1_status = 'checked';
    }
    else if ($selected_radio == 'giss2') {
    $giss2_status = 'checked';
    }
        
        $body = "From: $college
        Street Address: $streetaddress
        E-Mail: $contactemail
        Phone Number: $phone
        Contact Email: $contactemail
        GISS Session: $selected_radio";
    
        echo "We've recived your contact information $to! We will be in Contact with you shortly!" ;
        
        mail($to, $subject, $body); 
        
    //These are the variables for the email
    
    $sendto = $_POST['contactemail']; // this is the email address collected form the form
    $ccto = "my@email.com"; //you can cc it to yourself
    $subject = "Registration"; // Subject
    $message = "Thank you for registering. Here are the registration details you have provided:
    You are registered for:$selected_radio
    
    College:$college
    Address:$streetaddress
    City:$city
    State:$state
    Contact Person:$contactperson
    Contact Email:$contactemail
    .......";
    
    // This is the function to send the email
    if(mail($sendto, $subject, $message, $header)) header("location: attendee.html"); 
    } 
    
    ?>
    <script type=text/javascript>
    setTimeout("location.href='index.html'", [3000]);
    </script>
    I'm a PHP amateur and have been working on this project for hours so now it's all starting to look like gibberish.

    Thanks so much!

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Can you please post the html form here. That will help us understand whats going on in the PHP. Most likely its a naming problem and not even PHP, but the only way to know that is for us to see the form code ...and didn't I just work with you on this script, lol...
    Thanks,
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Lol why, yes you did. Then the client wanted radio buttons and that sent me right back to feeling brain damaged. Original problems were fixed though!

    Here's the form code:

    Code:
    <form action="home_contact.php"  method="post" id="frmcontactform" >
     <div>
     <p>*Asterisk denotes mandatory field</p>
      <fieldset>
       <div><label for="college">*College</label>
            <input type="text" name="college" id="college" size="41" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="streetaddress">*Street Address</label>
            <input type="text" name="streetaddress" id="streetaddress" size="35" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="city">*City</label>
            <input type="text" name="city" id="city" size="27" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div style="padding-bottom:12px"><label for="state">*State</label>
            <input type="text" name="state" id="state" size="2" />
       </div>
       <div><label for="zip">*Zip</label>
            <input type="text" name="zip" id="zip" size="5" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="contactperson">*Contact Person</label>
            <input type="text" name="contactperson" id="contactperson" size="22" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="contactemail">*Contact Email</label>
            <input type="text" name="contactemail" id="contactemail" size="23" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="phone">*Phone</label>
            <input type="text" name="phone" id="phone" size="10" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div>
            <label for="fax">Fax</label>
            <input type="text" name="fax" id="fax" size="11" />
     </div>
      </fieldset>
      <br />
        <fieldset>
       <div>
           Please select the GISS session you plan to attend<P>
    <input type="radio" name="giss1" id="giss1" value="GISS I" />GISS I
    <input type="radio" name="giss1" id="giss1" value="GISS I" />GISS II
     <br />
     </div>
      </fieldset>
      <div class="centerac"><input type="submit" name="submit" id="submit" value="Submit to Enter Attendee Information" />
       </div>
     <br />
     </div>
     </form>
    Thanks again!

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I believe that radio buttons work exactly the same way as a select menu or even just a text input: their value is sent as $_POST['fieldname'].

    One obvious problem in the html is that the values are both the same. Is this intentional? Is this a typo while pasting the code here? If not, I bet that's the whole problem.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    sorry that was a typo in pasting here. lol. I've been up too long.

    Code:
    <form action="home_contact.php"  method="post" id="frmcontactform" >
     <div>
     <p>*Asterisk denotes mandatory field</p>
      <fieldset>
       <div><label for="college">*College</label>
            <input type="text" name="college" id="college" size="41" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="streetaddress">*Street Address</label>
            <input type="text" name="streetaddress" id="streetaddress" size="35" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="city">*City</label>
            <input type="text" name="city" id="city" size="27" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div style="padding-bottom:12px"><label for="state">*State</label>
            <input type="text" name="state" id="state" size="2" />
       </div>
       <div><label for="zip">*Zip</label>
            <input type="text" name="zip" id="zip" size="5" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="contactperson">*Contact Person</label>
            <input type="text" name="contactperson" id="contactperson" size="22" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="contactemail">*Contact Email</label>
            <input type="text" name="contactemail" id="contactemail" size="23" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div><label for="phone">*Phone</label>
            <input type="text" name="phone" id="phone" size="10" />
       </div>
      </fieldset>
     <br />
      <fieldset>
       <div>
            <label for="fax">Fax</label>
            <input type="text" name="fax" id="fax" size="11" />
     </div>
      </fieldset>
      <br />
        <fieldset>
       <div>
           Please select the GISS session you plan to attend<P>
    <input type="radio" name="giss1" id="giss1" value="GISS I" />GISS I
    <input type="radio" name="giss2" id="giss2" value="GISS II" />GISS II
     <br />
     </div>
      </fieldset>
      <div class="centerac"><input type="submit" name="submit" id="submit" value="Submit to Enter Attendee Information" />
       </div>
     <br />
     </div>
     </form>
    The only thing not showing up in the emails is the radio button selection (GISS I or GISS II).

    Thanks
    Last edited by kairick; 06-10-2010 at 06:40 AM. Reason: amended code

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    What happens if you submit the form and use the following line?
    <?php print_r($_POST); ?>
    That should tell you how to deal with the data.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    where would I enter that line? After "value" in the HTML? Do I customize the line as
    Code:
    <?PHP print $giss1_status; ?>
    or leave it as is?

    Thanks

  8. #8
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Here's my updated php code. I don't think I posted the print_r($_POST) correctly.

    Code:
    <?php
    
       
     if(($_POST['college']=="")||($_POST['streetaddress']=="")||($_POST['city']=="")||($_POST['zip']=="")||($_POST['state']=="")||($_POST['contactperson']=="")||($_POST['contactemail']=="")||($_POST['phone']=="")||($_POST['fax']=="")||($_POST['giss1']=="")||($_POST['giss2']==""))
     {
      echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
      if($_POST['college'] == ""){ echo "<li>*College</li>"; }
      if($_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
      if($_POST['city'] == ""){ echo "<li>*City</li>"; }
      if($_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
      if($_POST['state'] == ""){ echo "<li>*State</li>"; }
      if($_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
      if($_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
      if($_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
      echo "</ul><p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p></body></html>";
     }
     
     if(isset($_POST['submit'])) {
    
        $to = "my@email.com"; 
        $subject = "Contact Has Registered";
        $college = $_POST['college'];
        $streetaddress = $_POST['streetaddress'];
        $city = $_POST['city'];
        $state = $_POST['state'];
    	$zip = $_POST['zip'];
        $contactperson = $_POST['contactperson'];
        $contactemail = $_POST['contactemail'];
    	$phone = $_POST['phone'];
    if ($selected_radio == 'giss1') {
    $giss1_status = 'checked';
    print_r($_POST);
    }
    else if ($selected_radio == 'giss2') {
    $giss2_status = 'checked';
    print_r($_POST);
    }
        
        $body = "From:$college
        Street Address:$streetaddress
    	City:$city
    	State:$state
    	Zip Code:$zip
        E-Mail:$contactemail
        Phone Number:$phone
        Contact Email:$contactemail
        GISS Session:$selected_radio";
    
        
        mail($to, $subject, $body); 
        
    //These are the variables for the email
    
    $sendto = $_POST['contactemail']; // this is the email address collected form the form
    $ccto = "my@email.com"; 
    $subject = "Registration"; 
    $message = "Thank you for registering.
    
    Here are the registration details you have provided:
    
    You are registered for:$selected_radio
    
    College:$college
    Address:$streetaddress
    City:$city
    State:$state
    Zip:$zip
    Contact Person:$contactperson
    Contact Email:$contactemail";
    
    // This is the function to send the email
    if(mail($sendto, $subject, $message, $header)) header("location: attendee.html"); 
    } 
    
    ?>
    <script type=text/javascript>
    setTimeout("location.href='index.html'", [3000]);
    </script>
    Last edited by kairick; 06-10-2010 at 07:04 PM. Reason: removed emails for security

  9. #9
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Try just putting it at the top of the page and copy the output here. It's not showing up because $selected_radio is not being set to any $_POST value. It looks as if your copying 100% of your code off of some tutorial site and your not copying all of it. Just a guess.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  10. #10
    Join Date
    Mar 2010
    Location
    Washington, DC
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    The basic form was generated using SiteGrinder 2 (It was only initially supposed to be basic.) but as the client wanted features added to the form (email, confirmation, redirect, now radio buttons), it gradually became pieced together from a couple of sources.

    So to clarify, I'm posting print_r($_POST) at the top of the page (after <?php ) and copying the result here?

Bookmarks

Posting Permissions

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