Create A Form
1. Create a Form in Dreamweaver. Be sure to note the names of your text fields as your create them. This will be important for later on.
In this tutorial you will learn three way to proces the data entered into your form:
- Spit the data back out to an HTML page.
- e-mail the data to an e-mail address
- Send the information to a SQL database that can be stored and recalled at a later time.
Spit the data back out to an HTML Page:
1. Select New from the File Menu. Create a new basic page. Save it as form.php and save it in the same directory as your form page (or if you wish create a separate directory for php scripts, you'll need to remember to reference this directory when you fill in the form action).
For the purpose of this exercise we will assume you have four form items and named them thusly:
| Meaning | Name of text box in form |
| First Name | fname |
| Last Name | lname |
| Color of Your Eyes | ecolor |
| Favorite Song | song |
2. Type the following code in the form.php page between the body tags:
<?php
print "Hello $_POST[fname] $_POST[lname]. You have lovely $_POST[ecolor] eyes. I would love to gaze into them as we listen to $_POST[song] together."
?>
3. Save the document. Things to note:
- php documents start with <?php and end with ?>
- The print statement is used to print back to the screen
- $_POST_[variable] is used to call up the value that was entered into the text box in your html document
4. Open your html document. Find the Form Tag:
<form action="form.php" method="POST">
Make sure the method is POST and the form action matches the name of your php document.
5. Upload both documents. If everything is working correctly after hitting 'Submit' a new page should appear with your information in it.
Let's now proceed to formatting and sending the data via e-mail. CONTINUE