Simple Form Handling with PHP

October 25th, 2008

I’ve seen some requests lately on how to handle form data. It’s pretty easy, and here is the most basic way of doing it. There isn’t any validation, or styling with CSS - just three separate files. You could actually do this with a little javascript/css and some php and do everything in one file - but like I said, this is the most basic way of doing it.

Your HTML Form

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" “http://www.w3.org/TR/html4/strict.dtd”> <html> <head> <title>A simple form</title> </head> <body> <h1>A form</h1> <form action=”mail.php” method=”post”> <label for=”theName”>Name:</label><br> <input type=”text” name=”name” id=”theName”><br> <label for=”theEmail”>Email Address:</label><br> <input type=”text” name=”email” id=”theEmail”><br> <label for=”theMessage”>Message:</label><br> <textarea name=”message” id=”theMessage”></textarea><br> <input type=”submit” value=”send”> </form> </body> </html>

Your php file

<?php //enter the address to send the form to $toAddress = “someone@somewhere.com”; //enter the subject of the email you recieve $subject = “Contact from Web”; //enter the path to the file where the user gets sent to after submitting the form $thankYou = “thanks.php”; $name = $_REQUEST['name']; $email = $_REQUEST['email']; $message = $_REQUEST['message']; $body = “ $name $email $message”; mail($toAddress, $subject, $body, “From: $email”); header(”Location: $thankYou”); ?>

download

Tags: , ,

One Response to “Simple Form Handling with PHP”

  1. clientside or serverside for e mail form - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more Says:

    October 25th, 2008 at 10:26 am

    [...] did a quick little demo that has the files for download so you can see how they all work together. Simple Form Handling with PHP __________________ FNA Cotton, fna CSS help | cool t-shirts | [...]

Leave a Reply

Name:

Email (will not be published):

Website:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>