radio button problem with php

Hi,

Okay I’ve been trying to get php to retrieve my posted check or unchecked radio button to pass from one form to another to allow a person to see their choice before submitting their order form.

It’s posting right now with some code I’m fiddling with, but I can’t get it to pass anything but a value, which I don’t care about right now. I just want the checked option to pass to the next form.

Any help will be extremely helpful in preventing me from bashing my head into a wall. I want this done with php code preferably.

Here’s my mockup radio button code (I got sick of filling out my original form just to test this):

[php]

<?PHP $Visa = 'unchecked'; $Master = 'unchecked'; $Amex = 'unchecked'; if (isset($_POST['Submit'])) { $selected_radio = $_POST['cc']; if ($selected_radio == 'Visa') { $Visa = 'checked'; } else if ($selected_radio == 'Master') { $Master = 'checked'; } else if ($selected_radio == 'Amex') { $Amex = 'checked'; } } ?>

[/php]

Here’s the form:

<form id="promo_order_form" name="promo_order_form" method="post" action="verify_order_form.php">

  <span id="spryradio1">
  <label>
    <input name="cc" type="radio" id="Visa" value="Visa" />
    Visa</label>
  <br />
  <label>
    <input type="radio" name="cc" value="Master" id="Master" />
    Mastercard</label>
  <br />
  <label>
    <input type="radio" name="cc" value="Amex" id="Amex" />
    Amex</label>
</span>

    <br />
    <hr />
    <input type="submit" name="Submit" id="Submit" value="Submit" />
    <br />


</form>

Here’s the page it’s going to:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HMC Promotional Items</title>
<link href="css/hmcpromo_secure.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationRadio.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationRadio.css" rel="stylesheet" type="text/css" />

<?php

//Order Form Var
$Order_Date = strip_tags($_POST['Order_Date']);
$Date_Needed = strip_tags($_POST['Date_Needed']);
$AU = strip_tags($_POST['AU']);
$Approved = strip_tags($_POST['Approved']);
$mgrEmail = strip_tags($_POST['mgrEmail']);
$Contact = strip_tags($_POST['Contact']);
$Email = strip_tags($_POST['Email']);
$Phone1 = strip_tags($_POST['Phone1']);
$Fax = strip_tags($_POST['Fax']);
$MAC = strip_tags($_POST['MAC']);
$Ship = strip_tags($_POST['Ship']);
$Attention = strip_tags($_POST['Attention']);

//Personal Form Radio
$selected_radio = $_POST['cc'];

//Personal Order Form Var
//$Visa = strip_tags($_POST['Visa']);
//$Master = strip_tags($_POST['Master']);
//$Amex = strip_tags($_POST['Amex']);
$CardNum = strip_tags($_POST['CardNum']);
$exp = strip_tags($_POST['exp']);
$cvs = strip_tags($_POST['cvs']);
$auth = strip_tags($_POST['auth']);

//Personalization Form Var
$First = strip_tags($_POST['First']);
$Last = strip_tags($_POST['Last']);
$Phone2 = strip_tags($_POST['Phone2']);
$Email2 = strip_tags($_POST['Email2']);

//Item Form Var and Math
$ItemNum = strip_tags($_POST['ItemNum']);
$ItemPrice = strip_tags($_POST['ItemPrice']);
$ItemNum = strip_tags($_POST['ItemNum']);
$Qty = strip_tags($_POST['Qty']);
$Total = strip_tags($_POST['Total']);

//Totals Form Math
$Subtotal = strip_tags($_POST['Subtotal']);
$Sales_Tax = strip_tags($_POST['Sales_Tax']);
$P_H = strip_tags($_POST['P_H']);
$Freight = strip_tags($_POST['Freight']);
$Totals = strip_tags($_POST['Totals']);

?> 

</head>

<body>

<div id="logo"><img src="images/wfhm_bw_logo.jpg" width="272" height="114" /></div>

<div>
<h1>Executive Metal Grip Roller</h1>
<h2>Personalized Promotional Items</h2>
<br />
<p>
  The cost of items ordered will be deducted from branch P&amp;L. If this is a personal order, complete credit card information below. <strong>Order form must be filled out completely.</strong> If you do not receive an email acknowledgment of your order within 2 business days, please call 1-800-535-1395 to verify receipt.</p>
</div>

<form id="promo_order_form" name="promo_order_form" method="post" action="">

<div id="order_form">
<span id="sprytextfield7">
<label for="Order_Date">Order Date:</label>
    <input type="text" name="Order_Date" id="Order_Date" value='<?php echo htmlentities($Order_Date) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    <br />
<span id="sprytextfield17">
    <label for="Date_Needed">Date Needed:</label>
    <input type="text" name="Date_Needed" id="Date_Needed" value='<?php echo htmlentities($Date_Needed) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    <br />
<span id="sprytextfield16">
    <label for="AU">AU #:</label>
    <input type="text" name="AU" id="AU" value='<?php echo htmlentities($AU) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    (Required for ALL orders, including credit card orders)
    <br />
    <br />
<span id="sprytextfield15">
    <label for="Approved">Approved by:</label>
    <input type="text" name="Approved" id="Approved" value='<?php echo htmlentities($Approved) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span></span>
    <br />
    (Managers approval required)
    <br />
    <br />
<span id="sprytextfield5">
    <label for="mgrEmail">Manager Email:</label>
    <input type="text" name="mgrEmail" id="mgrEmail" value='<?php echo htmlentities($mgrEmail) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    <br />
<span id="sprytextfield14">
    <label for="Contact">Contact:</label>
    <input type="text" name="Contact" id="Contact" value='<?php echo htmlentities($Contact) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span></span>
    <br />
    <br />
<span id="sprytextfield13">
    <label for="Email">Email:</label>
    <input type="text" name="Email" id="Email" value='<?php echo htmlentities($Email) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    <br />
<span id="sprytextfield12">
    <label for="Phone1">Phone #:</label>
    <input type="text" name="Phone1" id="Phone1" value='<?php echo htmlentities($Phone1) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    <br />
<span id="sprytextfield8">
<label for="Fax">Fax #:</label>
<input type="text" name="Fax" id="Fax" value='<?php echo htmlentities($Fax) ?>' />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    <br />
    <br />
<span id="sprytextfield9">
    <label for="MAC">MAC #:</label>
    <input type="text" name="MAC" id="MAC" value='<?php echo htmlentities($MAC) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span></span>
    <br />
    <br />
<span id="sprytextfield10">
    <label for="Ship">Ship to:</label>
    <input type="text" name="Ship" id="Ship" value='<?php echo htmlentities($Ship) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span></span>
    <br />
    <br />
<span id="sprytextfield11">
    <label for="Attention">Attention:</label>
    <input type="text" name="Attention" id="Attention" value='<?php echo htmlentities($Attention) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span></span>
    <br />
    <br />
</div>

<div id="personal_form">
  <div id="personal_header">PERSONAL ORDERS ONLY:</div>

  <span id="spryradio1">
  <label>
    <input type="radio" name="cc" value="Visa" id="Visa"  />
    Visa</label>
  <br />
  <label>
    <input type="radio" name="cc" value="Master" id="Master" />
    Mastercard</label>
  <br />
  <label>
    <input type="radio" name="cc" value="Amex" <?PHP print $male_status; ?> id="Amex" />
    Amex</label>
</span>

  <span id="sprytextfield21">
  <label for="CardNum">Card Number:</label>
  <input type="text" name="CardNum" id="CardNum" value='<?php echo htmlentities($CardNum) ?>' />
  <span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
  <br />
  <br />
  
  <span id="sprytextfield18">
  <label for="exp">EXP:</label>
  <input name="exp" type="text" id="exp" size="10" maxlength="5" value='<?php echo htmlentities($exp) ?>' />
  </span>
  
  <span id="sprytextfield20">
  <label for="cvs">CVS #:</label>
  <input name="cvs" type="text" id="cvs" size="5" maxlength="3" value='<?php echo htmlentities($cvs) ?>' />
  <span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
  <br />
  <br />
  <span id="sprytextfield19">
  <label for="auth">Name on Card:</label>
  <input name="auth" type="text" id="auth" size="40" value='<?php echo htmlentities($auth) ?>' />
</span>
</div>

<div id="delivery">
	<p>Please allow 3 weeks for delivery.
	<br />
	<br />
	Orders will ship via UPS Ground. Individual product styles will ship separately.
  </p>
</div>

	<br />
<ul>
  <li class="clear">PERSONALIZATION INFORMATION</li>
</ul>

<div id="pers_form">
<span id="sprytextfield3">
    <label for="First">First Name:</label>
    <input type="text" name="First" id="First" value='<?php echo htmlentities($First) ?>' />
    <span class="textfieldRequiredMsg">A value is required.</span></span>
    
<span id="sprytextfield2">
    <label for="Last">Last Name:</label>
    <input type="text" name="Last" id="Last" value='<?php echo htmlentities($Last) ?>' />
	<span class="textfieldRequiredMsg">A value is required.</span></span><br /><br />
    
<span id="sprytextfield4">
	<label for="Phone2">Phone #:</label>
    <input type="text" name="Phone2" id="Phone2" value='<?php echo htmlentities($Phone2) ?>' />
    <span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    
<span id="sprytextfield1">
 	<label for="Email2">Email:</label>
    <input type="text" name="Email2" id="Email2" value='<?php echo htmlentities($Email2) ?>' />
    <span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
</div>

<div id="totals_header">
TOTAL COST
</div>

	<br />
<ul>
  <li>ITEM</li>
</ul>

<div id="item_form">
  <h3>Executive Metal Grip Roller</h3>
    <input name="ItemNum" type="hidden" id="ItemNum" value="EMGR" />
    <br />
    <input name="ItemPrice" type="text" id="ItemPrice" value="$1.10 Each" size="12" readonly="readonly" />
    <br />
    <br />
<span id="sprytextfield6">
<label for="Qty">Qty (Minimum 300):</label>
<input name="Qty" type="text" id="Qty" size="10" value='<?php echo htmlentities($Qty) ?>' />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMinValueMsg"><br />The entered value is less than the minimum required.</span></span><br />
    <br />
    <hr />
	<label for="Total">Total:</label>
    <input name="Total" type="text" id="Total" size="25" readonly="readonly" />
</div>

<div id="totals_form">
  <label for="Subtotal">Subtotal</label>
  <input name="Subtotal" type="text" id="Subtotal" size="15" readonly="readonly" />
  <br />
  <br />
  <label for="Sales_Tax">Sales Tax (MN only)</label>
  <input name="Sales_Tax" type="text" id="Sales_Tax" size="15" />
  <br />
  <br />
  <label for="P_H">Packaging and Handling</label>
  <input name="P_H" type="text" id="P_H" value="$3.75" size="15" readonly="readonly" />
  <br />
  <br />  
  <label for="Freight">Freight</label>
  <input name="Freight" type="text" id="Freight" size="15" readonly="readonly" />
  <br />
  <hr />
  <label for="Totals">Total</label>
  <input name="Totals" type="text" id="Totals" size="15" readonly="readonly" />
</div>

<div id="thank_you">
	<center><h3>Thank you for your order!</h3>
	<p class="font_red">Please verify the information and click the button to submit your order.</p>
	<br />
	<input name="Confirm" type="submit" class="font_bold" value="Confirm" />
	</center>
</div>

<div class="clear"><!--CLEAR--></div>

</form>

<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "email", {isRequired:false, useCharacterMasking:true});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {validateOn:["change"]});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "none", {validateOn:["change"]});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "phone_number", {isRequired:false, useCharacterMasking:true});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "email", {validateOn:["change"], useCharacterMasking:true});
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "integer", {minValue:300, validateOn:["change"]});
var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "date", {useCharacterMasking:true});
var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8", "phone_number", {useCharacterMasking:true});
var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9");
var sprytextfield10 = new Spry.Widget.ValidationTextField("sprytextfield10");
var sprytextfield11 = new Spry.Widget.ValidationTextField("sprytextfield11");
var sprytextfield12 = new Spry.Widget.ValidationTextField("sprytextfield12", "phone_number", {useCharacterMasking:true});
var sprytextfield13 = new Spry.Widget.ValidationTextField("sprytextfield13", "email", {validateOn:["change"], useCharacterMasking:true});
var sprytextfield14 = new Spry.Widget.ValidationTextField("sprytextfield14");
var sprytextfield15 = new Spry.Widget.ValidationTextField("sprytextfield15");
var sprytextfield16 = new Spry.Widget.ValidationTextField("sprytextfield16", "integer");
var sprytextfield17 = new Spry.Widget.ValidationTextField("sprytextfield17", "date", {useCharacterMasking:true});
var spryradio1 = new Spry.Widget.ValidationRadio("spryradio1", {isRequired:false});
var sprytextfield18 = new Spry.Widget.ValidationTextField("sprytextfield18", "none", {isRequired:false});
var sprytextfield19 = new Spry.Widget.ValidationTextField("sprytextfield19", "none", {isRequired:false});
var sprytextfield20 = new Spry.Widget.ValidationTextField("sprytextfield20", "integer", {isRequired:false});
//-->
</script>
</body>
</html>

Have you attempted an array?


  <span id="spryradio1">
  <label>
    <input name="cc[]" type="radio" id="Visa" value="Visa" />
    Visa</label>
  <br />
  <label>
    <input type="radio" name="cc[]" value="Master" id="Master" />
    Mastercard</label>
  <br />
  <label>
    <input type="radio" name="cc[]" value="Amex" id="Amex" />
    Amex</label>
</span>

Once you make it an array value (name[]) - you can pass it off to the handler portion that you have already written:

[php]
if (isset($_POST[‘Submit’])) {
$selected_radio = $_POST[‘cc’];
if ($selected_radio == ‘Visa’) {
$Visa = ‘checked’;
} else if ($selected_radio == ‘Master’) {
$Master = ‘checked’;
} else if ($selected_radio == ‘Amex’) {
$Amex = ‘checked’;
}
}
[/php]

and you should see the results you are looking for.

Just remember: Any time you are working with checkboxes in forms, it’s always best to use some sort of array… associative or otherwise. Because then, you are able to sort out the data based on the common “name” of the boxes.

Hope this helps!

Wow, I just re-read your post, looked at my post, and I think I had misunderstood the first go-around. Are you trying to throw the first $_POST[“cc”] from one page to the next? I would just load it up into a sessions var and transport it out to the final destination. That would require you going through and putting session_start(); on every page (if not already done) and then when they input the data into the form, just process it out into sessions vars:

$_SESSION[“cardType”] = $_POST[“cc”];

I have a multi-part form on my site where I ran everything through a switch() statement for the different steps of the form. I had to put all the user-input data into $_SESSION[vars] in order to transport it from one case ‘’: to the next.

Sorry about that. But yeah… IMHO, loading all of the form input into $_SESSION vars and then dumping it into the absolute last processor is the best way to do it. Unless you have another form along the way, then you can just include it in the next form with a hidden input field

i.e.

then you can $_POST it into the next form or the handler and handle the flow of data that way.

Sponsor our Newsletter | Privacy Policy | Terms of Service