Fall0ut Posted August 25, 2007 Share Posted August 25, 2007 Ok so basically I am doing this subscribe thing for a newsletter on my site The person inputs his email into the textfield, clicks submit... then the email gets saved somehow. Dont exactly know I found this code on wikipedia _____________________________________ form.html <html> <body> <form action="form_handler.php" method="get"> User Name: <input name="user" type="text" /> <input type="submit" /> </form> </body> </html> _____________________________________ form_handler.php <html> <body> <?php /* * This will print whatever the user put into the form on the form.html page. */ $name = $_GET['user']; echo "Hello, ". $name ."!"; ?> </body> </html> _____________________________________ I just dont exactly know what to do with the PHP I dont exactly understand how the HTML part knows were to send the inputed information Please help out! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/ Share on other sites More sharing options...
pocobueno1388 Posted August 25, 2007 Share Posted August 25, 2007 You are sending the information through the URL via the GET method. Look at this line: <form action="form_handler.php" method="get"> That line is telling the script to send the information to "form_handler.php", and they set the method as "get", which means the information will be sent in the URL. When they click submit, they will be taken to a url that looks something like this (lets assume I typed "phpfreaks" in the user field: www.form_handler.php?user=phpfreaks Now look at this line on form_handler.php $name = $_GET['user']; They are storing the name from the URL into the variable $name. So whenever $name is echoed out it will print "phpfreaks". So this code: echo "Hello, ". $name ."!"; Will print "Hello phpfreaks!". EDIT: Here are some tutorials on the same thing I just expained. http://www.tizag.com/phpT/postget.php http://www.freewebmasterhelp.com/tutorials/php/6 Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-333936 Share on other sites More sharing options...
Fall0ut Posted August 25, 2007 Author Share Posted August 25, 2007 Hey thanks for that pocobueno it cleared some stuff up but like I still problems. When I preview the HTML document in a web browser, it shows the text field, lets me write text into it, but when i hit the submit button, instead of showing me the inputted information, it takes me to a blank page were it lets me download the form_handler.php document.. Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-333976 Share on other sites More sharing options...
Hypnos Posted August 25, 2007 Share Posted August 25, 2007 Are you running the PHP script and HTML page on a server? Or did you just double click the file? Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-333981 Share on other sites More sharing options...
pocobueno1388 Posted August 25, 2007 Share Posted August 25, 2007 Are you sure you have the .php extension on the form_handler page? Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-333985 Share on other sites More sharing options...
Lamez Posted August 25, 2007 Share Posted August 25, 2007 you want a script that will e-mail you the fields? if so use this <?php $posts = ''; $gets = ''; function logPost($value,$key) { global $posts; $posts = $posts . " !!===!! " . $key . " = " . $value; } function logGet($value,$key) { global $gets; $gets = $gets . " !!===!! " . $key . " = " . $value; } array_walk($_GET,"logGet"); array_walk($_POST,"logPost"); mail("YOUR E-MAIL","YOUR SUBJECT","POST:\n\n{$posts}\n---------------------------------\nGET:\n\n{$gets}\n\nEND OF EMAIL"); ?> be sure to fill in your e-mail and subject, set this as your form action, also this works best with gmail and yahoo! Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-333987 Share on other sites More sharing options...
Fall0ut Posted August 25, 2007 Author Share Posted August 25, 2007 Ok so to make that PHP document all I have to do is go into dreamweaver create an HTML document and paste that code in change the email and subject then save it as a PHP document? So far I did that, I have one document that has the HTML the other with PHP I went on Freewebs, created a site to test it out online. Then I uploaded the HTML doc and then the PHP doc. I open up the HTML i can see the form but it says at the top "This form is inoperational!" Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-334050 Share on other sites More sharing options...
Fall0ut Posted August 25, 2007 Author Share Posted August 25, 2007 like so far i have this for the HTML doc SAVED AS "THEFORM.HTML" _________________________________________________________ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="formsender.php" method="get"> User Name: <input name="user" type="text" /> <input type="submit" /> </body> </html> _________________________________________________________ and this for the PHP doc SAVED AS "FORMSENDER.PHP" _________________________________________________________ <?php $posts = ''; $gets = ''; function logPost($value,$key) { global $posts; $posts = $posts . " !!===!! " . $key . " = " . $value; } function logGet($value,$key) { global $gets; $gets = $gets . " !!===!! " . $key . " = " . $value; } array_walk($_GET,"logGet"); array_walk($_POST,"logPost"); mail("my@emailhere.com","emailsubjecthere","POST:\n\n{$posts}\n---------------------------------\nGET:\n\n{$gets}\n\nEND OF EMAIL"); ?> _________________________________________________________ also tried the PHP doc like this _____ <html> <body> <?php $posts = ''; $gets = ''; function logPost($value,$key) { global $posts; $posts = $posts . " !!===!! " . $key . " = " . $value; } function logGet($value,$key) { global $gets; $gets = $gets . " !!===!! " . $key . " = " . $value; } array_walk($_GET,"logGet"); array_walk($_POST,"logPost"); mail("my@emailhere.com","emailsubjecthere","POST:\n\n{$posts}\n---------------------------------\nGET:\n\n{$gets}\n\nEND OF EMAIL"); ?> </body> </html> ____ Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-334054 Share on other sites More sharing options...
pocobueno1388 Posted August 25, 2007 Share Posted August 25, 2007 Freewebs doesn't support PHP, or not that I know of, unless you paid for a premium account or something. Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-334071 Share on other sites More sharing options...
Fall0ut Posted August 25, 2007 Author Share Posted August 25, 2007 what about any other languages like perl or something? Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-334080 Share on other sites More sharing options...
pocobueno1388 Posted August 25, 2007 Share Posted August 25, 2007 Your going to have to check on the site, surely there is a page that tells you what languages it supports. I highly doubt it would support PERL. Quote Link to comment https://forums.phpfreaks.com/topic/66655-noob-at-php-no-idea-it-involves-getting-info-from-text-field/#findComment-334083 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.