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. W3Schools Forms Tutorial: W3Schools Form Attributes: W3Schools Form Elements: W3Schools Input Types: W3Schools Form Attributes: Caution: It is OK if you are reluctant to put your
real personal home address and personal phone number on the Web. 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 Reminder: .style1 or autostyle7 are not a meaningful names: -5 for each occurance HTML Form Tutorials belowInteractive W3Schools Forms TutorialsMake sure you MEET ALL GRADING CRITERIA below. |
||||||||||||||||||||||||
Topic | Directions | Points | You still need A unique <title> briefly describing your pageMeta Description: <meta name="description" content="Longer Page Description"> The same Stylesheet: <link href=" SiteName.css" rel="stylesheet" type="text/css"> The same <nav>, <header> <footer> and stylesheet (.css) as your Home page and ResumeA comment for each closing </div> Example: </div> <!-- close wrapper -->If you do not have a security certificate your URL/Web address is http://site.com, not https://site.com |
Points -5 -5 -10 -10 -3 -1 |
||||||||||||||||||||
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: |
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. 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...> |
||||||||||||||||||||||
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> |
|||||||||||||||||||||||
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"> </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. |
Many 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.
<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. (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 the required fields, such a requiring FirstName? 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]. Upload to server:
|
||||||||||||||||||||||
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 --> hidden" name="redirect" value="contactSent.htm"> <table > input type="text" name="FirstName" id="FirstName" size="40"
required> <input type="text" name="LastName" id="LastName" size="40"
required> email"
name="Email" id="Email" size="40"
required> textarea name="Comments" rows="5" cols="42"></textarea> </td> input type="reset" name="" value="Reset"> input type="submit" name="" value="Submit"> <!-- Name="" so "Submit" does not show Submit=Submit on email to recipient --> </td>
|
||||||||||||||||||||||||
|