Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Retrieving radio button information in PHP

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

    Default

    print_r() displays the contents of a variable. We need to find out what $_POST contains: that is all the information sent through the "post" method-- in other words, all of the information from your form.
    Look through the output (best to view it in view>source) and find the value corresponding to the field in your form.

    To be entirely clear-- ALL you are doing is displaying what was sent so you know how to work with it.

    You can insert this code before EVERYTHING else on the page as-is:
    <?php print_r($_POST); exit(); ?>

    That will print out the info then stop execution: you will only get the values of POST, then after that just remove that line from the top and use your page like normal-- but then you'll know what values are being sent.

    Additionally, I recommend testing this several times to find out what the possible values are-- try clicking one radio button, clicking none, clicking the others.... etc.
    Once you identify a pattern that is reliable, you can program PHP to do the same. But until you know what you're looking for, it's just a guess in PHP, and especially from us here since we can't test it.
    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

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

    Default

    No change. Where do I set the $selected_radio $POST value?

    I have the post values up top for 'giss1' and 'giss2'. Would I put the 'selected_radio' up there too?

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

    Default

    Do you have a link you could give us? Or just post the resulting output when<?php print_r($_POST); exit(); ?> is pasted at the absolute top and a form is submitted to the page.
    -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*

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

    Thumbs up Issue Resolved!

    Turns out I was all screwed up. Here's the new code:

    Inserted into head:
    Code:
    <?PHP
    $selected_radio = $_POST['session'];
    print $selected_radio;
    ?>
    form:
    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="session" id="giss1" value="GISS I"><?php print$giss1_status;?> 
    GISS I
    <br />
    <input type="radio" name="session" id="giss2" value="GISS II"><?php print$giss2_status;?> 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>
    PHP
    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>"; }
      if($_POST['session'] == "unchecked") { echo "<li>You must select a GISS session</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 ($selected_radio == 'giss1') {
    $giss1_status = 'checked';
    }
    else if ($selected_radio == 'giss2') {
    $giss2_status = 'checked';
    }
     
     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'];
    $selected_radio = $_POST['session'];
    print $session;
    }    
        $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); 
        
    
    $sendto = $_POST['contactemail']; 
    $ccto = "my@email.com"; 
    $subject = "Registration"; 
    $message = "Thank you for registering.
    
    You are registered for:$selected_radio
    
    College:$college
    Address:$streetaddress
    City:$city
    State:$state
    Zip:$zip
    Contact Person:$contactperson
    Contact Email:$contactemail";
    
    if(mail($sendto, $subject, $message, $header)) header("location: attendee.html"); 
    } 
    
    ?>
    <script type=text/javascript>
    setTimeout("location.href='index.html'", [3000]);
    </script>
    Thanks, everyone for your help!

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

    Default

    You're making this way too complex: read my posts carefully.

    This has nothing to do with your existing code, nor is it intended to "solve" anything-- this is going to help you/us diagnose the problem.


    Here's what you should do:
    1. Ignore all of the PHP you have. Don't delete it, just don't use it for now.
    2. Create a new php file called "phpnew.php"
    3. In that file, paste exactly and only <?php print_r($_POST); ?> and NOTHING else.
    4. Temporarily change the action of your HTML form to "....../phpnew.php" (the location of this new page).
    5. Test it!!! Try different values in the form. See what the result is on the PHP page.
    6. Find the pattern in the results from the radio buttons. What are you looking for? Is it "1" or "0"? Is it text? Is it being sent correctly? Then once you figure this out post the results here and we can try to help you figure out if the problem is in the PHP or in the HTML form.


    This is a tool for diagnosing what is happening: it will tell us what data is actually being sent (and received by PHP) so we know what to do next.
    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

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
  •