Someone recently posted to make a Form Processing script so people would know how to use forms with there scripts.
Quote:
|
Originally Posted by Danny Needs Help
Form Processing/Mailing would be a good first tutorial :).
|
Well here you go. First of all you need to know a little HTML so you know how to make forms. Then you make you form. For instance:
<html>
<head>
<title>Form Processor</title>
</head>
<body>
FORM HTML
Code:
<form action='something.php' method='post'>
<table cellpadding='0' cellspacing='0'>
<tr>
<td>
<input type='text' name='VARIABLE_NAME' />
</td>
</tr>
<tr>
<td>
<input type='submit' value='Process Data' />
</td>
</tr>
</table>
</form>
</body>
</html>
something.php
PHP Code:
<?php
echo $_POST['VARIABLE_NAME'];
?>
There... Now you are wondering how does that work. Whatever you make the name of the form the value makes the variable set on the next page. I added $_POST[''] around the variable so it knew to get the data from a method on named post. in <form we added method='post' you can make it method='get' also. Which basically means you put $_GET[''], the difference is post is run hidden. Get puts all the variables in the url and gets the data from the url in other words for sites that have something.php?id=61102 to get the id you use $_GET['id'] it is just 2 different ways of putting the data to the next page. Most people like the post way to hide data like passwords but others like to show it to make there URL look cooler plus so people can send the url to a friend and it will automatically process the data. For instance if you made a script that calculated just using url you could make a file like:
calculator.php
PHP Code:
<?php
echo $_GET['data'];
?>
Then all you have to do is go to calculator.php and in url put: calculator.php?data=5+5-8*1/8 which will output: 0.25 on the page.
now to go back to the old method "post" you could make a form and on the page make a text box called "to" and someone put there eMail address there.Now on the page that the form sends the data to
just make it print $to and it will print what they typed. Now if you wanted to use what I said on the mail() tutorial you could do something like make a html
form then make the names... to, subject, body. then on the next page type: mail($to, $subject, $body, "From: My Feedback"); and you just made a feedback. Now
your probably wondering how does the html file know where to send the data. Well just change action='' in the <form> to the address of the PHP file and away you go.
Good luck!