dan_t Posted February 8, 2009 Share Posted February 8, 2009 Hi, Somehow I lost my last post. I took a class last year on php where we worked with a form. we did it so fast that I never really understood what we did. My question is how do I get my input from the text box in the form to an if - else statement? here is a small example: <html> <head> <title>Forms!!</title> </head> <body bgcolor="#cccccc"> <?php if ($_GET['form.php']) { echo ('data = '.($_GET["name"])); } ?> <form action="form.php" method="get"> <p>This is to be sent:<input type="text" name="value" /></p> <input type="submit" name="submit" value="send" /> <input type="reset" name="reset" value="redo" /> </form> </body> </html> I used the get method so I could view it in the browser. It says value= whatever I type in, but how do I grab it? Please help me understand, if you wouldn't mind. Thanks Dan Quote Link to comment Share on other sites More sharing options...
trq Posted February 8, 2009 Share Posted February 8, 2009 Given that form, your php would look like.... <?php if (isset($_GET['submit'])) { echo 'data = ' . $_GET['value']; } ?> Quote Link to comment Share on other sites More sharing options...
dan_t Posted February 8, 2009 Author Share Posted February 8, 2009 OK, so lets say I wanted an if else statement that said: if answer were blue echo good job else Try again. How would I go about that? Dan Quote Link to comment Share on other sites More sharing options...
trq Posted February 8, 2009 Share Posted February 8, 2009 Given this form.... <form action="form.php" method="get"> <p>What is your favourite color?<input type="text" name="color" /></p> <input type="submit" name="submit" value="send" /> <input type="reset" name="reset" value="redo" /> </form> <?php if (isset($_GET['submit'])) { if ($_GET['color'] == 'blue') { echo "good job"; } else { echo "Try again"; } } ps: You might want to start with the Hudzilla link in my signiture, this is very basic stuff. ?> Quote Link to comment Share on other sites More sharing options...
dan_t Posted February 10, 2009 Author Share Posted February 10, 2009 Thank you very much for your help. On your first answer, why wouldn't you get the form name (form.php or whatever) instead of the "submit" name? Thanks and thanks for the link, I have read quite a bit. It kind of puts some of the pieces together. We blew by alot of the stuff in that class so fast that I never really understood what or why we were doing certain things. I'm finally after a year starting to understand (a little). Dan 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.