Jump to content

how to pass 2 radio buttons?


BigD
 Share

Recommended Posts

I have a form radioButtonG passing 2 radio buttons grp1 and grp0 to code radioButtonA. I am having difficulty to receive these 2 buttons. Please help. Thanks. radioButtonG -<html><FORM NAME ="form1" METHOD ="POST" ACTION ="radioButtonA.php"><head><title>Radio Buttons</title></head><?PHP$aray2 = array("Tom", "Jan");$i = 0;foreach ($aray2 as $key => $value){echo $value;echo "<INPUT TYPE = \"Radio\" Name =\"grp.$i\" value= \"male\" >Male";echo "<INPUT TYPE = \"Radio\" Name =\"grp.$i\" value= \"female\" >Female";echo "\n";echo '<input type=hidden name="aray2[]" value="'.htmlspecialchars($value).'">';}?><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Submit"></FORM></html> radioButtonA -<html><head><title>Radio Buttons action</title></head><FORM NAME ="form2" METHOD ="PUT" ACTION ="radioButton2.php"><?PHP$aray2 = $_POST['aray2'];$grpx = $_REQUEST['grp0'];$grpy = $_REQUEST['grp1'];print_r($aray2);?><input name="grpx" value="<?php echo $grpx; ?>" /><input name="grpy" value="<?php echo $grpy; ?>" /><input name="aray2" value="<?php echo $aray2; ?>" /><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Next"></FORM></html>

Link to comment
Share on other sites

I fixed the code to increment $i. On the receiving code I tried $_REQUEST['grp0'], $_REQUEST[grp1], and $_REQUEST['grp.0'],$_REQUEST['grp1']; none worked. <html><FORM NAME ="form1" METHOD ="POST" ACTION ="radioButtonA.php"><head><title>Radio Buttons</title></head><?PHP$aray2 = array("Tom", "Jan");$i = 0;foreach ($aray2 as $key => $value){echo $value;echo "<INPUT TYPE = \"Radio\" Name =\"grp.$i\" value= \"male\" >Male";echo "<INPUT TYPE = \"Radio\" Name =\"grp.$i\" value= \"female\" >Female";echo "\n";$i = $i + 1;echo '<input type=hidden name="aray2[]" value="'.htmlspecialchars($value).'">';}?><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Submit"></FORM></html> radioButtonA code:<html><head><title>Radio Buttons action</title></head><FORM NAME ="form2" METHOD ="PUT" ACTION ="radioButton2.php"><?PHP$aray2 = $_POST['aray2'];$grpx = $_REQUEST['grp0'];$grpy = $_REQUEST['grp1'];print_r($aray2);?><input name="grpx" value="<?php echo $grpx; ?>" /><input name="grpy" value="<?php echo $grpy; ?>" /><input name="aray2" value="<?php echo $aray2; ?>" /><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Next"></FORM></html>

Link to comment
Share on other sites

I figured it out. The problem was I have a dot in my variable names. that can create problems. I am able to pass things to a third piece of code. This is a great forum. Thanks to people who posted. Here are the codes: xxxxG:<html><FORM NAME ="form1" METHOD ="POST" ACTION ="radioButtonA.php"><head><title>Radio Buttons</title></head><?PHP$aray2 = array("Tom", "Jan");$i = 0;foreach ($aray2 as $key => $value){echo $value;echo "<INPUT TYPE = \"Radio\" Name =\"grp$i\" value= \"male\" >Male";echo "<INPUT TYPE = \"Radio\" Name =\"grp$i\" value= \"female\" >Female";//echo "<INPUT name = \"$grp.$i\" value = \"grp.$i\" type = hidden>";echo "\n";$i = $i + 1;echo '<input type=hidden name="aray2[]" value="'.htmlspecialchars($value).'">';}?><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Submit"></FORM></html> xxxxA:<html><head><title>Radio Buttons action</title></head><FORM NAME ="form2" METHOD ="PUT" ACTION ="radioButton2.php"><?PHP$aray2 = $_POST['aray2'];$grpx = $_REQUEST['grp0'];$grpy = $_REQUEST['grp1'];echo "grp0 is $grpx, \n";echo "grp1 is $grpy. \n";print_r($aray2);?><input name="grpx" value="<?php echo $grpx; ?>" type=hidden ><input name="grpy" value="<?php echo $grpy; ?>" type=hidden ><input name="aray2" value="<?php echo $aray2; ?>" type=hidden ><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Next"></FORM></html> xxxx2<html><head><title>Radio Buttons action2</title></head><?PHP$aray3 = $_REQUEST['aray2'];$grp3 = $_REQUEST['grpx'];echo "value to next level is $grp3";?></html>

Link to comment
Share on other sites

I run into another problem. While changing the 2nd piece code to a loop, I can not get grp$i translated to grp0 and grp1. Anyone following the tpoic please try the code: <html><head><title>Radio Buttons action</title></head><FORM NAME ="form2" METHOD ="PUT" ACTION ="radioButton2.php"><?PHP$aray2 = $_POST['aray2'];print_r($aray2); $i = 0;while (array_shift($aray2)) {$grpp = $_REQUEST['grp$i'];echo "grpp is $grpp, \n";$i++;}?><input name="grpp" value="<?php echo $grpp; ?>" type=hidden ><input name="aray2" value="<?php echo $aray2; ?>" type=hidden ><INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Next"></FORM></html>

Link to comment
Share on other sites

PHP replaces periods and a few other characters in input names with underscores, because of a shortsighted feature in PHP that no one uses anymore. If you want to keep the original names you can use this:

function getRealPOST() {  $pairs = explode("&", file_get_contents("php://input"));  $vars = array();  foreach ($pairs as $pair) {    $nv = explode("=", $pair);    $name = urldecode($nv[0]);    $value = urldecode($nv[1]);    $vars[$name] = $value;  }  return $vars;}$_POST = getRealPOST();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...