Cetanu Posted August 19, 2009 Share Posted August 19, 2009 Okay, I've tried fixing this forever! I thought I had a handle on forms and PHP. >.> <.< I would like this: 1) Member comes to page. 2) Answers yes or no (via Radio Form) 3) Depending on choice, header to new location. (via if...elseif...else ) It won't work! Nothing happens!!!!! No header. Nothing. >.> <.< I think it's because I'm using radio buttons. <form action="rpgtest.php" method="post"> <fieldset> <legend>Do You Have a Character?</legend> <input type="radio" name="Pos" id="yes" value="Yes"/>Yes, I do.<br/> <input type="radio" name="Pos" id="no" value="No"/>No, I need one!<br/> <br/> <input type="submit" name="submit" id="submit" value="Go!"/> </fieldset> </form> <?php if($_POST['yes'] && $_POST['submit']){ header('Location: http://mythscape.freezoka.com/chrisrpg/'); } elseif($_POST['no'] && $_POST['submit']){ header('Location: http://mythscape.freezoka.com/chrisrpg/create.php'); } else { echo "After selecting a choice you will be redirected to the appropriate page."; } ?> Link to comment https://forums.phpfreaks.com/topic/171051-solved-radio-buttons-driving-me-insane/ Share on other sites More sharing options...
kratsg Posted August 19, 2009 Share Posted August 19, 2009 You need to use $_POST['Pos'] for this. Only the name attribute of the form input gets used to contain the POST/GET variable. In your script, you're using the id="" identifiers. Link to comment https://forums.phpfreaks.com/topic/171051-solved-radio-buttons-driving-me-insane/#findComment-902116 Share on other sites More sharing options...
Cetanu Posted August 19, 2009 Author Share Posted August 19, 2009 So how could I distinguish between Yes and No? Link to comment https://forums.phpfreaks.com/topic/171051-solved-radio-buttons-driving-me-insane/#findComment-902118 Share on other sites More sharing options...
kratsg Posted August 19, 2009 Share Posted August 19, 2009 Based on it's value... <?php if($_POST['Pos'] == "yes"){//do this }elseif($_POST['Pos'] == "no"){//do something else }else {//throw an error saying that they made an invalid choice } ?> Link to comment https://forums.phpfreaks.com/topic/171051-solved-radio-buttons-driving-me-insane/#findComment-902119 Share on other sites More sharing options...
Cetanu Posted August 19, 2009 Author Share Posted August 19, 2009 Oh, thanks! Link to comment https://forums.phpfreaks.com/topic/171051-solved-radio-buttons-driving-me-insane/#findComment-902120 Share on other sites More sharing options...
Cetanu Posted August 19, 2009 Author Share Posted August 19, 2009 Now I get the white screen of doom. <form action="rpgtest.php" method="post"> <fieldset> <legend>Do You Have a Character?</legend> <input type="radio" name="Pos" id="yes" value="Yes"/>Yes, I do.<br/> <input type="radio" name="Pos" id="no" value="No"/>No, I need one!<br/> <br/> <input type="submit" name="submit" id="submit" value="Go!"/> </fieldset> </form> <?php if($_POST['Pos'] == "Yes"){ header('Location: http://mythscape.freezoka.com/chrisrpg/'); } elseif($_POST['Pos'] == "No"]){ header('Location: http://mythscape.freezoka.com/chrisrpg/create.php'); } else { echo "Invalid choice. Try again."; } ?> EDIT: NEVERMIND. Link to comment https://forums.phpfreaks.com/topic/171051-solved-radio-buttons-driving-me-insane/#findComment-902133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.