CiTi · Computer Coding · Year One · Unit 3
A lesson within “My First Website & Server-Side Management”
What are databases? What should be stored in DBs vs. files?
Before data can be stored anywhere, it has to be collected, and on the web that happens through a form. This lesson builds the collecting half: a real contact form whose answers travel to the server and arrive as an email. The same form-to-server path is what later lessons will point at a database instead of an inbox.
Demonstrates understanding in:
Web Construction Website Planning & Construction Incorporating Design Elements Code Type via SyntaxHands-On:
#1 Write valid, semantic HTML5
#2 Style with CSS
#7 Validate and debug my own work
Professional:
#4 Communicate to a non-technical audience
#7 Treat a mistake as data, not failure
Clear written communication: labels, instructions, and error messages a stranger can follow on the first try. Tracing a data flow: following one answer from a box, through its name, to the server, and into an email.
Designing for every user, including keyboard and screen-reader users (labels, groups, required markers). Testing the unhappy paths (empty fields, a page opened directly), not only the happy one, and noticing what still needs fixing.
Building an accessible form with fieldset, legend, label, text, email, and phone inputs, a select, a textarea, and required vs. optional fields; styling it with CSS; choosing POST over GET; and writing a WebDNA handler page that sends the form as an email with [sendmail].
Students will understand how an HTML form hands data to a server-side page, and why the browser’s checks alone are not enough: and will add a styled, accessible contact form to MySite that emails each message to them.
fieldset and legend, and connect every label to its field with for and id.[sendmail].required is not enough on its own.Every student ships a working contact form on a live site that delivers real email, the same feature nearly every business site has. Push further: pairs send each other real messages through their forms (a bug report, a question) and each developer replies by email, moving toward “Authentic Audience / Client.”
vars.inc (pathvar, cssvar, incvar, imgvar) and the three includes working (previous lesson), plus a contact/ pagefromvar. Mail servers like Gmail reject or spam-folder messages whose From domain does not allow the sending server, so use an address on a domain that permits it.emailvar (where their messages arrive).required stops them if a starred field is empty.
name and value to contact/send.html using POST.
send.html runs [sendmail] with the answers.
| GET | POST | |
|---|---|---|
| Where the data travels | In the address bar: send.html?c_name=Jordan&c_comments=... | Inside the request, out of sight |
| Saved in history and bookmarks | Yes, with all the answers | No |
| Best for | Searches and filters you might want to bookmark | Anything that sends a message or changes something |
A contact form sends a message and may contain a phone number, so it uses method="post". Break It experiment 2 switches to GET so students can see the difference.
The form goes in the bodycopy of contact/index.html, under the page’s usual top lines.
fieldset draws a box around related fields; legend is its title. Screen readers announce the legend with each field inside it (“About You, Name”).
for="c_name" connects the label to the field with id="c_name". Clicking the label jumps into the box, and screen readers read the label aloud.
The server only receives fields that have a name. In send.html, name="c_name" becomes [c_name]. The c_ stands for “contact” and keeps field names easy to spot.
Adding required stops the browser from submitting while that field is empty. Phone is left optional. A select can only be required if its first option has value="". The red star plus the note at the top tell users which fields are required.
type="email" makes the browser check for an @ and shows an email keyboard on phones. type="tel" shows a number pad. type="text" accepts anything.
<input type="hidden" name="c_send" value="yes"> is never shown, but it is always sent with the form. A direct visit to send.html has no c_send. The next lesson (True or False: showif & hideif) wraps [sendmail] in a check for it, so the page only sends when the form was used.
textarea is a multi-line box (rows sets its starting height). select is a drop-down; each option’s value is what gets sent.
Two new settings go in vars.inc, and one new page, contact/send.html, receives the form and sends the email.
emailvar is where messages arrive (the student’s own address). fromvar is the address the teacher provides (see Materials & Prep).
Every form field arrives on send.html as a WebDNA value with the same name: name="c_comments" becomes [c_comments]. The page sends one email using those values, then shows a Thanks page built with the normal includes. There are no checks yet: the page sends every time it loads (see Tricky Part 1). Checking the fields on the server comes in a follow-up lesson.
[sendmail]’s settings (to, from, subject) are separated by &, the same way as a URL. Everything between the opening and closing tags becomes the email’s text, including the date, time, and the sender’s IP address from [ipaddress], which the My First Website project asks for.
The server-side results below were tested on our WebDNA server (without sending mail). Each has a Break It experiment on the walkthrough.
required is not a lockrequired only works when someone uses the form in a browser. Anyone can open send.html directly, or a program can send it data, and this version of send.html sends an email every time. On a direct visit no fields are sent, so the email shows each field as its own name in brackets, like [c_name] (tested on our server). This is the problem the follow-up lesson solves with server-side checks.
Try it: remove required from the Name field and submit with Name empty. The email still arrives, with a blank name.
With method="get", every answer, comments and phone number included, appears in the address bar and is saved in the browser history.
Try it: change the form to method="get", submit, and read the address bar. Change it back.
name is never sentA field can look perfect and still send nothing if its name is missing or doesn’t match send.html. The server sees it as never sent, so the email shows its name in brackets instead of the answer.
Try it: delete name="c_comments" from the textarea and submit a complete form. The email’s Comments line says [c_comments].
If for and id don’t match exactly (capital letters count), the page looks the same, but clicking the label no longer jumps into the box and screen readers lose the label.
Try it: change one label’s for to a wrong value, then click the label.
[sendmail] runs every time its page runsWebDNA runs [sendmail] every time the page loads, so it must only live in send.html. Reloading the Thanks page makes the browser ask to resend the form; saying yes sends a second email. Never paste a [sendmail] example into a normal page: on our server, one in a lesson page sent a broken message on every view and jammed the mail queue for six days.
[sendmail] settingsPut visitor answers only in the email’s text, never inside the tag’s settings (to, from, subject). Those settings are split on &, so visitor text there could add or change settings. That is why the subject is a fixed “MySite Contact Form” and the contact type goes in the body.
[sendmail] before students test. A tag with a missing or broken to or from can jam the whole server’s mail queue, not just that student’s. Glance at vars.inc for real addresses in emailvar and fromvar.action path is wrong); emailvar is spelled right; the spam folder; then the From address (Materials & Prep).name attributes and send.html. A mismatch shows up in the email as the field’s name in brackets.mail.jpg for one of their own images.send.html directly sends another email. Warn students before testing so inboxes don’t fill with duplicates.| Time | Phase | What happens |
|---|---|---|
| 5 min | Warm-Up / Hook | Show two real contact forms: a clean, labeled one and a messy one. Pairs list what makes the good one easy (groups, labels, stars, clear button). |
| 15 min | Direct Instruction | Build the form live: form, two fieldsets with legends, labels with for/id, input types, select, textarea, required. Show that clicking a label jumps into its box. Explain name as “the label the server sees.” |
| 20 min | Guided Practice | Students add the form to contact/index.html (walkthrough Part B) and test required by submitting with fields empty. |
| 10 min | Independent Practice | Students add the form CSS to style.css (Part C) and adjust colors to match their site. |
| 5 min | Check-In | Pairs test each other’s forms by keyboard only (Tab through every field). Preview Day 2: “Right now Submit goes nowhere.” |
| Time | Phase | What happens |
|---|---|---|
| 5 min | Warm-Up | “Where do the answers go when you click Send?” Collect guesses, then walk the How It Works flow. |
| 15 min | Direct Instruction | GET vs. POST. Read send.html line by line: the [sendmail] settings, the email text with the field values, and the Thanks page. Stress where [sendmail] lives and why form data stays out of its settings. |
| 20 min | Guided Practice | Students add emailvar and fromvar to vars.inc, create send.html, point the form’s action at it, and send one real test message (Part D). |
| 10 min | Break It | Pairs run Break It experiments 1 through 4, predicting first. Confirm the email for a full form arrived with date, time, and IP. |
| 5 min | Exit Ticket | Cliffhanger: open a finished send.html directly in the address bar and show the email that arrives full of bracketed names. “Next lesson, we fix that.” Exit ticket on the walkthrough. |
Formative: Live check of each contact page: two fieldsets with legends; every label connected; text, email, select, and textarea fields with name, email, type, and comments required and phone optional; CSS styling applied; POST to send.html; a complete form shows Thanks and delivers an email with date, time, and IP.
Exit ticket (completion-graded): “Your form already uses required. Give one way someone could still send you an empty or junk message through send.html. Then explain why the form uses POST.”
Extension: (1) Send a copy to the teacher with cc= in the [sendmail] settings. (2) Add autocomplete="name" and autocomplete="email" so browsers can fill the form in for visitors.