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 Link to comment https://forums.phpfreaks.com/topic/144385-php-communication/ 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']; } ?> Link to comment https://forums.phpfreaks.com/topic/144385-php-communication/#findComment-757649 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 Link to comment https://forums.phpfreaks.com/topic/144385-php-communication/#findComment-757655 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. ?> Link to comment https://forums.phpfreaks.com/topic/144385-php-communication/#findComment-757660 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 Link to comment https://forums.phpfreaks.com/topic/144385-php-communication/#findComment-759226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.