Home   CGS 2820C
  Web Development
#11 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.

Option: If you choose to rebuild your website in WordPress, you can use a Contact Form Plugin to easily build your Contact page, such as Ninja Forms or WPForms. Then submit the absolute WordPress URL address to the Canvas assignment Dropbox.

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

Server: The main network computer that supplies centralized software and connects local client computers together or to 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 - the owner of the website. 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: A typical home or business computer connected to a server. You can build, edit, test and view HTML files on a client computer. 
You can build and edit PHP and ASP files on a client computer, but you cannot test and view them unless you install server software.
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 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 html form code samples:
<form name="contactForm" id="contactForm" action="FormProcess.php" method="post">

Download FormProcess.php (right-click the FormProcess.txt file and save it as FormProcess.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 a single 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 / download data from a database. Post is most common.

The Text Fields, TextAreas, CheckBoxes, and Radio button elements on your form are called Fields. Fields hold the form data, that is the names, address, phone number...

If you do not include the type attribute in an <input> field 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).

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.

The user can move from field to field to enter values by either tapping [Tab], or by using the mouse. [Enter] will "Submit" the form.

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.

HTML Form Tutorials below

Interactive W3Schools Forms Tutorials

Make sure you MEET ALL GRADING CRITERIA below.

Topic Directions Points
1. Add only one 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.

In DreamWeaver:
Insert | Form, then select the desired control

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 and personalized banner/masthead 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>
Only 1 form!

(p 144, 171, 341-342)

There is a
Troubleshooting
link at the bottom of the page.
3. If you have not already done so, 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 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 important input tags:
<input type="text" name="FirstName" id="FirstName" size="40" required>

Have at least one field that is not required.

Validate email with type="email" to
make sure email is both required and valid - that is, at minimum it must have an @.
<input type="email" name="email" id="email" required>
(p 440-443)
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
City
ST
Zip
* Email
Gender M F
Education AS BS
Comments

Optional pattern and placeholder:

<input name="Zip" type="text" pattern="[0-9]{5}" title="Five digit zip code">

<textarea cols="40" name="Comments" placeholder="Enter feedback here" rows="4"></textarea>

10 <input...>
Name, City, State, Zip
10 type "email"
10 set required fields

(p 168, p 343)

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 technique, 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.

<head>
<style type="text/css">
label {
   width: 100px;
   float: left; text-align: right;
   padding-right: 20px; margin-bottom: 10px; }

input {
   width: 150px; margin-bottom: 10px; }
</style>
</head>

<body>
<form name="contactForm" action="FormProcess.php" method="post">
  <label for="FirstName">*
First Name</label>
  <input name="FirstName" type="text"
required><br>
  <label for="
address">Address</label>
  <input name="
address" type="text" pattern="[A-Za-z0-9]+"><br>
  <label for="email">
* Email</label>
  <input name="email" type="email"><br>
  <input name="Submit" type="submit" value="Submit">
</form>

<!-- pattern and placeholder are samples and optional -->
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...
In DreamWeaver: 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

Ex: FirstName
Not First Name
(no spaces)
Not Text1
(not descriptive)
Set State (as a Dropdown, default to FL, with a max length for value attribute=2)
<option value="FL" selected>Florida</option>
Open the text file StatesOptionValue.txt
For more info on State Abbreviations see:
https://www.youtube.com/watch?v=dLECCmKnrys
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 State dropdown

(p 157)
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 checkboxes

(p 155)
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">
or
<input type="checkbox" name="Agree" value="Agree">
I Agree
10 checkboxes
OR radio buttons

(p 156)
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
(Textarea)
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

(p 425-425)
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 Submit Button

Optional working Reset Button
<input type="submit" name="" value="Submit">
Optional Reset button will clear all fields
Ex: <input type="reset" name="Reset" value="Reset">
10 submit
reset is optional

(p 431)
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]
   contact.htm
   favicon.ico
(may be in images folder)
   index.htm
   newsletter.htm
   portfolio.htm
   resume.htm
   yourSiteName.css
   FormProcess.php

Test on multiple browsers: such as Edge, FireFox, Chrome, Safari and smartphone.

Most hosting companies provide built-in server side form processing scripts. These scripts are the form "action." 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).

Sample Server Side script:
<form name="contactForm" id="contactForm" action="FormProcess.php" method="post">
You cannot open Php files online, so right-click the FormProcess.txt file and save it as FormProcess.php. 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 statement name="redirect" 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. To verify it works: Do a screen capture of the email you receive after filling out the form (use the Snipping Tool or Alt + Print Screen)
5. Upload both the complete URL address AND the Screen Capture (20 points)
to the assignment Dropbox. See:
.../2820Web/Forms/SampleEmailScreenCapture.jpg

Checklist:
1. Did you set required fields?
2. Is the email type set as email (to validate the @)?
3. Did you set a Confirmation Message or Confirmation Page?
4. Did you get an email message after hitting Submit?
5. Did you do a Screen Capture of the email to upload to the Dropbox along with the Contact page URL?

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

Grading:
When I grade this, the first thing I will do is hit [Submit] without entering any data and the data validation should prompt me that FirstName, LastName, Email, and Comments are required.
(p 165)

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.

10pts Upload to the dropbox a Screen Capture of the email that was sent after you hit [Submit].
10pts Also upload your Contact page URL address.

Upload to server:
contact.htm
contactSent.htm
FormProcess.php
(p 149, 151)

 

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. You can only have one <form> tag for the entire page.
    You can only have one </form> for the entire page.
2. Did you place the </form> tag after the Submit button?
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 address.
($email_to = "yourName@yourDomainName.com";) Did you enter your email address correctly?
5a. Did you upload both contact.htm and contactSent.htm to public_html in GoDaddy?
5b. Did you upload FormProcess.php to the same directory (such as public_html) in GoDaddy?
5c. Are all three files spelled consistently both on your server online and in the html references?
Remember, file names and field names are case sensitive.
LastName cannot be Last Name or Lastname or lastname because it is case sensitive.
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  is in the contact.htm and LastName is also shown 3 times in FormProcess.php.
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.
If you are using GoDaddy, and your PHP success/confirmation message is working as intended, and you are NOT receiving an email, you can try inserting the following lines of code into your PHP script, after the <php? tags and after the ini_set and if(isset([yourcodehere])) lines. Put the following along with the other variable definitions.
$mail-Host = "relay-hosting.secureserver.net";
$mail-Port = 25;
$mail-SMTPDebug = 0;
$mail-SMTPSecure = "none";
$mail-SMTPAuth = false;
$mail-Username = "";
$mail-Password = "";

8. It takes longer to receive form submissions than it takes to receive an email - there is more to process. If your test submission did not arrive after a few minutes, check your SPAM or JUNK or TRASH 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.
10. The key to debugging programs is to Make It As Simple As Possible. Save the two files that are not working in a different folder as a backup.
A. Rename your files as test.htm and test.php.
B. Delete every field and unneeded piece of code in your file except FirstName, LastName, Submit, and your email address in both the htm file and php file and then test it.
C. Once you get the very short and simple file to work, start copying and adding your own fields and code from your backup files one at a time till you see what code blows it up.
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">
<
table>
 <tr>
   <td style="text-align:center;" colspan="2"> Contact (Your Name)</td>
 </tr>
 <tr>
   <td style="width:250px; text-align:right">
   * <label for="FirstName">First Name</label>
   </td>
   <td><
input type="text" name="FirstName" id="FirstName" size="40"
required>
   </td>
 </tr>
 <tr>
   <td style="text-align:right"><label for="LastName">Last Name</label> </td>
   <td>
<input type="text" name="LastName" id="LastName" size="40" required>
   </td>
 </tr>
 <tr>
   <td style="text-align:right"><label for="Telephone">Telephone</label> </td>
   <td> <input type="text" name="Telephone" size="40"> </td>
 </tr>
 <tr>
   <td style="text-align:right">
   * <label for="Email">Email</label>
   </td>
   <td><input type="
email" name="Email" id="Email" size="40" required>
   </td>
 </tr>
 <tr>
   <td style="text-align:right"> <label for="Comments">Comments</label> </td>
   <td><
textarea name="Comments" rows="5" cols="42"></textarea> </td>
 </tr>
 <tr>
   <td>&nbsp;</td>
   <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 -->
   </td>
 </tr>
</table>
</form>
The root folder of your actual local 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 that 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. See Favicon Tutorial and Favicon Generator
    index.htm Your Home page (usually must be in lower case)
    newsletter.htm  
    portfolio.htm Your artwork, or books, or items for sale...
    resume.htm  
    FormProcess.php
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