drukpa Posted December 17, 2008 Share Posted December 17, 2008 Hi Guys, I need someone much smarter than me to tell me what I'm doing wrong here. I have 3 radio buttons, in the same form, with a submit button. I want my php to check which radio button is selected and based on this, redirect to another url. My HTML: <form name="form1" method="POST" action="../checkbox_radio.php"> <label> <input type="radio" name="bp" id="bp" value="1"> Option One</label> <label> <input type="radio" name="bp" id="bp" value="2"> Option Two</label> <label> <input type="radio" name="bp" id="bp" value="3"> Option Three</label> <input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit"> </form> my php file "checkbox_radio.php" <?PHP $URL1="http://www.mydomain.com/page1.html"; $URL2="http://www.mydomain.com/page2.html"; $URL3="http://www.mydomain.com/page3.html"; $selected_radio = '0'; if(isset($_POST['Submit'])) { $selected_radio = $_POST['bp']; if($selected_radio == '1') { //$option_one = 'checked'; header("Location: $URL1"); //exit; } elseif ($selected_radio == '2') { //$option_two = 'checked'; header("Location: $URL2"); //exit; } elseif ($selected_radio == '3') { //$option_three = 'checked'; header("Location: $URL3"); //exit; } } ?> Thank you! Drukpa Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/ Share on other sites More sharing options...
ngreenwood6 Posted December 17, 2008 Share Posted December 17, 2008 First off you should use the code tags. Secondly what isn't it doing that it should be? Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718052 Share on other sites More sharing options...
samoht Posted December 17, 2008 Share Posted December 17, 2008 Why don't you use a switch case? Switch ($_POST[bp]) { case 1: URL1; break; case 2: URL2; break; case 3: URL3; break; } Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718054 Share on other sites More sharing options...
drukpa Posted December 18, 2008 Author Share Posted December 18, 2008 Hi NGreenWood6 & Samoth, a - Apologies for not posting the code in the correct tag. b - NGreenWood6 - The redirecting isn't happening. I get a blank page. When I change the _POST to _GET i notice that the string also has an &x= and &y= values. I can only guess this is why the if statement check isn't working. The x & y values change all the time - I dont know where this is coming from to start with, otherwise I would've deleted the object if I could. Samoht - I tried the Switch statement - but i get the same result - the php file loads, appearing to load a page, then goes blank... Any ideas? Thanks guys... Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718634 Share on other sites More sharing options...
beansandsausages Posted December 18, 2008 Share Posted December 18, 2008 Just change it to how you want but that works as it stands. <?php if(empty($_GET['action'])) { ?> <form action="?action=check" name="myform" method="POST" /> URL ONE: <input type="radio" name="url" id="url" value="1" /> URL TWO: <input type="radio" name="url" id="url" value="2" /> URL THREE: <input type="radio" name="url" id="url" value="3" /> <br /> <input type="submit" value="submit" /> </form> <?php } ?> <?php if($_GET['action'] == "check" ) { $url = (int)$_POST['url']; if($url == 0 ) { echo " Error "; } elseif($url == 1 ) { echo " URL 1 "; } elseif($url == 2 ) { echo " URL 2 "; } elseif($url == 3 ) { echo " URL 3 "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718671 Share on other sites More sharing options...
ngreenwood6 Posted December 18, 2008 Share Posted December 18, 2008 You don't have to change your whole code like burnside tells you. It looks to me like you did not name the submit button change this: input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit"> to this: input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit" name="Submit"> All I did there was add the name tag. and oh yeah the method for the form does not have to be capitalized. <form name="form1" method="post" action="../checkbox_radio.php"> Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718683 Share on other sites More sharing options...
beansandsausages Posted December 18, 2008 Share Posted December 18, 2008 You don't have to change your whole code like burnside tells you. It looks to me like you did not name the submit button change this: input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit"> to this: input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit" name="Submit"> All I did there was add the name tag. Bah how could i of missed that GRRRR!!!! well done Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718685 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 You don't have to change your whole code like burnside tells you. It looks to me like you did not name the submit button change this: input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit"> to this: input type="image" src="../images/Add-To-Cart.gif" value="Submit" alt="Submit" name="Submit"> All I did there was add the name tag. Bah how could i of missed that GRRRR!!!! well done .......BURN!!!!!......... =) Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718688 Share on other sites More sharing options...
ngreenwood6 Posted December 18, 2008 Share Posted December 18, 2008 I do that sometimes too. Sometimes we tend to think it is more complex than it really is lol. Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718689 Share on other sites More sharing options...
beansandsausages Posted December 18, 2008 Share Posted December 18, 2008 i seen the value="Submit" and just assumet it was name="Submit" LOL who names there submit button submit anyway lol, Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-718690 Share on other sites More sharing options...
drukpa Posted December 21, 2008 Author Share Posted December 21, 2008 Thank you guys...That's tremendous! Who would've thought! Luckily i don't earn my living programming! I really do appreciate the input...and the 'read between the lines' name your buttons something other than 'Submit'... Lesson learnt. Happy holidays to everyone! Respectfully, Drukpa Quote Link to comment https://forums.phpfreaks.com/topic/137419-solved-smart-phper-needed-to-look-at-this/#findComment-720921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.