psquillace Posted June 24, 2009 Share Posted June 24, 2009 Hello All: I am writing a php snip or at least trying too where if one radio button is selected we go to this URL otherwise go to this URL. I started something like this but I get lost real quick after that because I never did an if else with radio buttons before. Any help would be appreciated. <?php if ($radio1 'selected' ? "http://"){ }else{ "http://" } sorry for such a hack job on that above I just don't know that much about php... Quote Link to comment Share on other sites More sharing options...
psquillace Posted June 24, 2009 Author Share Posted June 24, 2009 ok, I was able to learn for my self how this is supposed to get done <?php if(isset($_POST['radio00'])) header("location $url"); { $URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=8&Itemid=2" }else{ $URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=1&Itemid=3" } ?> in case anyone else needs it.... Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 24, 2009 Share Posted June 24, 2009 bit wrong the if() header() won't work for both URL cases. <?php if(isset($_POST['radio00'])) { $URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=8&Itemid=2" }else{ $URL="http://emrcontractor.com/index.php?option=com_content&view=article&id=1&Itemid=3" } header("location $URL"); ?> the correct way Quote Link to comment Share on other sites More sharing options...
celsoendo Posted June 24, 2009 Share Posted June 24, 2009 Hey! Remember that radio buttons are form elements. It means that it contains a name and a value, like other elements (type="text", textarea...). So, if you have a form like this: <form method="post" action=""> <input type="radio" name="myRadio" value="1" /> Option 1 <input type="radio" name="myRadio" value="2" /> Option 2 <input type="submit" value="Send" /> </form> On PHP, you can use $_POST['myRadio'] to retrieve the selected radio button: <?php $myRadio = intval($_POST['myRadio']); if ($myRadio === 2) { header("Location: http://www.address1.com"); die; } else { header("Location: http://www.address2.com"); die; } ?> Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 24, 2009 Share Posted June 24, 2009 haha yah good first post Quote Link to comment Share on other sites More sharing options...
psquillace Posted June 24, 2009 Author Share Posted June 24, 2009 oh ok, now I see what I did wrong. Thanks for the help on this, Paul Quote Link to comment 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.