Re: How to process data from forms
| From: | Ernest E Vogelsinger | Date: | Tue, 19 Nov 2002 00:35:53 +0000 |
| Subject: | Re: How to process data from forms | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125005@lists.php.net to get a copy of this message | ||
At 01:06 19.11.2002, one_gundam_war spoke out and said:
--------------------[snip]--------------------
>Ok. I am kind of new to PHP, but I have a question. I have a site, and it
You've got a lot of questions then I'm sure :)
Ok, let's start:
>has a system where people can apply. However, the mailto: system
>seems like
>it would be too much of a hassle, and I don't want to make users skip it
>just because they use webmail.
>
>So, does anyone know how to make the values in a form either automatically
>get e-mailed to an address (as in you just hit "submit" and it does it. does
>not involve the client's e-mail addy) or to write it to a data file (which I
>can then check and see individual responses in).
If you submit a form to a PHP script, the form variables are accessible in
a global associative array ($_GET for forms using the GET method, $_POST
for post forms, or $_REQUEST for both). You can easily hand these variables
to either an SQL statement, or to the mail() function for further processing.
Assume this little form:
<form action="mailform.php" method="post">
Enter your name here: <input type="text" name="name"><br>
What is your demand? <textarea name="demand"></textarea><br>
<input type="submit" value="send it up">
</form>
When the user clicks on "Send it up", your script named "mailform.php" gets
executed and can process the data:
--------------------------------------------
<?php
// put the stuff into SQL
$sql = 'insert into mytable (name, demand) values (\'' .
str_replace('\'', '\'\'', $_POST['name']) .
'\',' .
str_replace('\'', '\'\'', $_POST['demand']) .
'\')';
// mail that stuff to me
mail('me@mydomain.com', 'Form received from Webuser',
'Name: '.$_POST['name']."\n\nDemand:
".$_POST['demand']."\n\n" .
'Yours sincerely, ' . $_SERVER['PHP_SELF']);
?>
<h1>Thanks for klicking that button!</h1>
---------------------------------------------
This is of course kinda crude, untested, etc etc etc, but I hope you get
the basic idea. http://www.php.net/manual/en/ is a great
place to look up
anything you need.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/