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... Link to comment https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/ 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.... Link to comment https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/#findComment-862398 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 Link to comment https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/#findComment-862399 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; } ?> Link to comment https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/#findComment-862403 Share on other sites More sharing options...
pkedpker Posted June 24, 2009 Share Posted June 24, 2009 haha yah good first post Link to comment https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/#findComment-862404 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 Link to comment https://forums.phpfreaks.com/topic/163443-if-else-with-radio-buttons/#findComment-862405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.