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."; } ?> Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 } ?> Quote Link to comment Share on other sites More sharing options...
Cetanu Posted August 19, 2009 Author Share Posted August 19, 2009 Oh, thanks! Quote Link to comment 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. 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.