Home   CGS 2820C
  Web Development
#10 Grading Criteria for:
Tables and Forms. Part 2
Contact Form, Form Controls, Form Validation, Form Action

Description:  This is the second part of two assignments used to create a working Contact Form which will be a linked through your common Menu Navigation to the rest of your website. Your Contact page will have the same format, layout, CSS sheet, and same Navigation as your other pages.

Caution: It is OK if you are reluctant to put your real personal home address and personal phone number on the Web.

Server Side processing: This is where a script file on the Web Server processes the posted form data and sends an email containing the form data to an appropriate recipient. This is the way professional forms are done. Server side scripts are typically written in PHP (PHP originally stood for Personal Home Page) or ASP (Microsoft's Active Server Page), which must be installed on the server. Server side scripts only run online from a remote web server, and do not run on local computers, unless special software is installed. That means, although you can view and edit your PHP or ASP script locally, you cannot run and test it until you upload it to the server. And although you can view the results of your PHP or ASP script when it is run on the server, you cannot view the source PHP or ASP code online.

Client Side processing: The processing of the form data is done on the Client's computer using the user's email client program, such as Outlook. This is seldom done for two reasons: 1. Windows will often display a warning message indicating that a process is trying to access their email client. 2. If a form is filled out in the library or in a computer lab, typically an email client has not been configured so the form data will not be submitted.

Form Action:  This is what happens after [Submit] is clicked. Usually a separate server-side script file is called to process the submitted data from the form HTML file. Using a server side form action is the preferred method.
Server side samples:
<form name="contactForm" id="contactForm" action="FormProcess.php" method="post">

Download FormProcess.php (right-click the .txt file and save as .php) and view FormDemo.htm
Note1: You will have to edit and modify FormProcess.php to work with your form and your email.
Note2: SCF email accounts may not work with the php script; so use your Gmail, Hotmail, or other email address.
Note3: Each field in the FormProcess.php file must match each field in the Contact.htm file. For instance, you cannot use Telephone in the HTML file and use Phone in the PHP file. Also the field names are case sensitive. If you have an mismatch error nothing will see to happen, and the email will not go through. However, a file may placed in the public_html folder of the server, named error_log.txt. Open this file to look for help on mismatched fields if your email did not go through.

Form Method: Post the data to the Server or Get or download data from a database. Post is most common.
Form Encoding Type: ASCII (text/plain) or Unicode. Encoding is used in Client Side processing, which is not recommended.

The Text Fields, TextAreas, CheckBoxes, and Radio button elements on your form are called Fields. Fields hold the form data.

If you do not include the type attribute in an <input> tag, it becomes a text field by default. But for clarity, you should enter each form element type.

You can enter default values for fields by using the value=" " attribute (see below).

The user will move from field to field to enter values by either tapping [Tab], or by using the mouse. [Enter] will "Submit" the form.
When using the <select> and <option> field element, such as a list of items, users can use [Ctrl] to select two or more noncontiguous items, or [Shift] to select a contiguous series of items.

For Forms help using Expression Web see: eBook-Springer/ExpressionWeb3/Wise10EW-Forms.pdf
For Forms help using DreamWeaver see: eBook-Springer/DreamweaverCS4/Powers09CSSformsValidation.pdf

Reminder: .style1 or autostyle7 are not a meaningful names: -5 for each occurance
Reminder: Every web page needs a unique Title, specific for the page: -5
Reminder: Page must have: <meta name="author" content="Your Name"> and a unique Meta Description for the Contact page.

Topic Directions Points
1. Add a Form control to your Contact page. The open <form> tag will be just before your <table> tag. The </form> tag will be just after the </table> tag.

2. If desired, insert a Table inside the Form Control.
Note: Some DOCTYPEs do not allow <form> tags inside <table> tag - so your <form> tags need to go outside the <table> tags

Use the same personalize banner/masthead in the top row or on the top of the page consistent with the rest of your site.
DW: Insert | Form, then select the desired control
EW2: Task Panes | Tool Box | Form Controls
EW3: Panels | Tool Box | Form Controls
and drag a Form control to an appropriate area after the <body> tag of your Contact page. Insert a table  about 12 rows, 2 columns inside the <form> tags:
Table | Insert Table
Merge the columns in your first row for your form title.

Also be sure to add your website Navigation to your Contact Page.  Your Contact page will use the same format, layout, CSS sheet, and same Navigation as your other pages. 10 pts.

Note: you should only have one <form> tag and one </form> closing tag on your contact page.
10 <form>

Note the
link at the bottom of the page.
3. Place the Field Labels (First Name, Last Name, City, ST, Zip, Email... ) in column one. Right Justify the field labels in column one:
<td style="text-align:right">

The example at right is NOT a working form; it is just a pictorial sample, so do not highlight and copy it.

Be sure to somehow specify (in an obvious manner) which fields are required - for instance see red *s in sample form shown at the right. Consider defining a class in your css called .required with color: red and bold.

Also add required to input tag:
<input type="text" name="FirstName" id="FirstName" size="40" required>

<input type="email" name="email" id="email" required>
If you use a table: In column one, starting in row 2 type the field labels or descriptions of your form fields such as those shown below.

Title Goes Here
* First Name
* Last Name
* Email
Gender M F
Education AS BS
10 <input...

See the section immediately below for an alternative way to do a neatly lined up form without a table.

At right is code for a neatly aligned form without a table. Many webweavers prefer to avoid using tables with HTML5 and CSS3. You can use this techique, as long as your previous table assignment has been submitted and graded.

See output below:


Leave * Name blank and enter Abc for * Email then click [Submit] to see what happens.
<style type="text/css">
label {
   width: 100px;
   float: left; text-align: right;
   padding-right: 20px; margin-bottom: 10px; }

input {
   width: 150px; margin-bottom: 10px; }

<form name="contactForm" action="FormProcess.php" method="post">
  <label for="FirstName">
First Name</label>
  <input name="FirstName" type="text"
  <label for="
  <input name="
address" type="text"><br>
  <label for="email">
  <input name="email" type="email"><br>
  <input name="Submit" type="submit" value="Submit">
4. Place the Form Control Elements shown above (text boxes, check boxes, buttons) in column two. Include at least: First Name, Last Name, City, ST, Zip, Email, and a Radio button, Checkbox, and Comment field.

All fields must have meaningful names such as FirstName, LastName, City...
EW: Task Panes | Tool Box | Form Controls and drag the appropriate controls to column two.
DW: Insert | Form and choose the control
In Code view give an appropriate name for each control. For instance by default the "Input (text)" control for First Name will be: <input type="text" name="Text1">
Change to: <input type="text" name="FirstName">
Make sure there are no spaces in the input field name.
10 good names
Set State (as a Dropdown, default to FL, max length for value attribute=2)
<option value="FL" selected>Florida</option>
Open the text file StatesOptionValue.txt
Copy the entire file from <select> to </select>
In code view, find the State dropdown and paste the entire code from <select> to </select>
10 option dropdown
Radio buttons (also called option buttons) such as male/female or something similar where only one choice can be made. You must put them in a Group Box if there are multiple categories. Only one Radio button may be selected - make sure it has a meaningful field name.

<input type="radio" name="Gender" id="M" value="M">M
<input type="radio" name="Gender" id="F" value="F">F
Notice the same name, but different IDs. Use unique IDs with radio buttons or pages with multiple <form> elements.
10 radio buttons
or checkbox
Add at least one Checkbox (such Education: H.S., College or something similar). Multiple Checkboxes may be selected - make sure it has a meaningful field name. Ex:
H.S.<input type="checkbox" name="HS" value="HS">
<input type="checkbox" name="Agree" value="Agree">
I Agree
10 checkbox
or radio buttons
For another example with multiple checkboxes:
  <label for="CallTime">Best Time to Call</label>
  <input type="checkbox" name="CallTime" id="CallTimeAM" value="Morning">Day<br>
  <label for="CallTime">&nbsp;</label>
  <input type="checkbox" name="CallTime" id="CallTimePM" value="Evening">Evening<br>
Add a Comment or Memo field
Textareas allow for longer entries and provide a scrollbar when the text area becomes longer than the length of the Text Area box. Ex:
<textarea name="Notes" cols="40" rows="6"></textarea>
10 comment textarea
Notice how you can set a default value or directions for a textarea control:
<textarea name="Comments" cols="60" rows="3">Please provide feedback here!</textarea>
Add a working Reset Button
Add a working Submit Button
Reset button will clear all fields
Ex: <input type="reset" name="Reset" value="Reset">
10 submit
and reset
Validate your form, that is:
Require at least 3 fields.

Make sure email is both required and valid - that is, at minimum it must have an @.

Have at least one field that is not required.
The file FormProcess.php will validate and process your data. But be sure to set email type as email, and use required to set required fields.

10 validate

See Troubleshooting section below

Set the Form Action, Method and Encoding.

See HTMLformDemo-ClientSide.htm
See HTMLformDemo-ServerSide.htm
and other form demos in the same Forms folder.

Test it: Make sure you can send/receive Form data to your own email.

Click for sample Form data sent to an email by a Server Side Script.

At this point there should be:
images     [Dir]
(may be in images folder)


Test on multiple browsers: such as IE, FireFox, Chrome, Safari.
In Expression Web, you can right-click the <form> object and choose Form Properties. Click the [Options] button on the lower-left corner to set your form Action.

Most hosting companies provide built-in server side form processing scripts. These scripts are the form "action." For instance, GoDaddy used to automatically install webformmailer.php on Linux servers or gdform.php on Windows servers in the root directory, where your index,htm and contact.htm files are stored. (Sample ASP script). After GoDaddy went to the cPanel, they no longer provided form processing scripts, so I found and modified the following script for you to use: FormProcess.php
The form will not work unless your web page is uploaded to the Server (as in Server side).
(Before the cPanel, you had to go to the hosting company's Control Panel and click on Form Mail and enter the email address that the form data will be sent to.)

Sample 1 GoDaddy/Linux Server Side script:
<form name="contactForm" id="contactForm" action="FormProcess.php" method="post">
You will have to edit and modify FormProcess.php to work with your form and your email.

For Client Side
(NOT recommended due to Windows warning messages)
<form action="mailto:yourname@domain.com?Subject=Inquiry" method="post" enctype="text/plain">

After the form is submitted - use an acknowledgement form or message, stating something like: "Thank you for contacting us. We will get back to you as soon as possible."

A good way to do this is to copy your contact.htm form and name the copy as contactSent.htm. Delete all of the form fields that were used in the contact.html form, and then add your acknowledgement message to the contactSent.htm form.

See the name="redirect" statement shown near the top of the sample form code shown at the bottom of this page.

1. Upload your contact.htm file to your website.
2. Fill out your contact online form and hit [Submit].
3. Wait a few minutes, then open your home email and you should get a copy of the filled out form data.
4. Copy the email and paste it into notepad; save it as EmailText.txt.
5. Upload EmailText.txt (20 points) AND the URL
to the assignment Dropbox.
10 action


When I grade this, the first thing I will do is enter some sample data and then hit [Reset] and every thing should be reset.

Then I will hit [Submit] without entering any data and the data validation should prompt me that FirstName, LastName, Email, and Comments are required.

Then I will enter FirstName, LastName, Comments, and an Email without the @. It should prompt me that the email is not a valid email.

When I correctly enter all the required fields and hit [Submit], it should call a separate Contact sent page, stating thank you - see redirect code below.

Be sure to upload your email text that was sent after you hit [Submit] as well as your URL address.

Upload to server:

If you have problems: do an internet search or use the class discussion board.

Troubleshooting Your Contact Form:
(Note - certain email addresses may not work - so if you think your code is correct, try another email address from another provider, just to rule that out.)

1. There should only be one <form> tag for the entire page.
    You can only have one <form> tag for the entire page.
    You can only have one </form> for the entire page.
2. Did you have </form> after the Submit buttom?
3. Do you have the line below for the form action in contact.htm:
<form name="contactForm" id="contactForm" action="FormProcess.php" method="post">
4. There is an area up top in the FormProcess.php file where you enter your email. Did you do that correctly?
5.  Did you upload FormProcess.php to the same directory (such as public_html) in GoDaddy?
6. You must match the fields listed in FormProcess.php (you will see them listed 3 times) exactly with the fields in the contact.htm form.
For instance: LastName in contact.htm and LastName shown 3 times in FormProcess.php. LastName cannot also be Last Name or Lastname or lastname because it is case sensitive.
Is FirstName in contact.htm and shown 3 times exactly the same way in FormProcess.php
Is Address in contact.htm and shown 3 times exactly in FormProcess.php
Is City in contact.htm and shown 3 times exactly in FormProcess.php
7. If the email does not arrive after a few minutes, consider using a different email address in FormProcess.php. Sometimes GoDaddy considers contact form emails from the same domain to be Spam. That is, if your GoDaddy domain is MyDomain.com and your email address is Mike@MyDomain.com, it may not go through. The solution is to use a different email address such as Mike@Outlook.com.
8. It takes longer to receive form submissions than it takes to receive an email. If your test submission did not arrive after a few minutes, check your Spam or Junk folder.
9. See if a file was placed in the public_html folder of the server, named error_log.txt. It may be able to tell you if an error was encountered, such as a mismatched field.
Sample code for a small form that you can copy and paste into the <body> of a demo file

<!-- FormProcess.php or webformmailer.php... is a Server Side Script stored in the root folder -->
<!-- It receives the form input and passes it to the email address of the recipient -->

<form name="contactForm" id="contactForm" action="FormProcess.php" method="post">
<input type="
hidden" name="subject" value="MySiteName Contact Submission">
<!-- Use the line below for a Redirect to send Confirmation or to display Thank you -->
<input type="
hidden" name="redirect" value="contactSent.htm">
   <td style="text-align:center;" colspan="2"> Contact (Your Name)</td>
   <td style="width:250px; text-align:right">
   * <label for="FirstName">First Name</label>
input type="text" name="FirstName" id="FirstName" size="40"
   <td style="text-align:right"><label for="LastName">Last Name</label> </td>
<input type="text" name="LastName" id="LastName" size="40" required>
   <td style="text-align:right"><label for="Telephone">Telephone</label> </td>
   <td> <input type="text" name="Telephone" size="40"> </td>
   <td style="text-align:right">
   * <label for="Email">Email</label>
   <td><input type="
email" name="Email" id="Email" size="40" required>
   <td style="text-align:right"> <label for="Comments">Comments</label> </td>
textarea name="Comments" rows="5" cols="42"></textarea> </td>
input type="reset" name="" value="Reset">&nbsp;&nbsp;&nbsp;
input type="submit" name="" value="Submit">
   <!-- Name="" so "Submit" does not show Submit=Submit on email to recipient -->
The root folder of your actual local (USB thumb drive or C:\Users\UserName\Documents\My Web Sites\YourDomainName) and remote (webserver) website should look now like this:
 images      [Dir] This is a subFolder - All images except possibly favicon.ico go here 
    contact.htm (Note: Your server will have a file named something like: FormProcess.php for your form action.)
    contactSent.htm This lets the user know the the form was submitted. It is a modified copy of contact.htm displaying a friendly confirmation message instead of the form.
    favicon.ico This is often in the images folder
    index.htm Your Home page (usually must be in lower case)
    portfolio.htm Your artwork, or books, or items for sale...
Godaddy/Linux Script used to process forms - this file is only works on the server.
You will have to edit and modify FormProcess.php to work with your form and your email. To see the code used, view FormProcess.txt in the same folder.
    yourSiteName.css Your external stylesheet