← All Lessons Student Walkthrough →

CiTi · Computer Coding · Year One · Unit 3

HTML Forms & Sending Mail: A Contact Form for MySite

A lesson within “My First Website & Server-Side Management”

Program Computer Coding: Year 1
Unit 3: My First Website & Server-Side Management
Duration Two class periods (~55 min each): forms, then sending
Grouping Individual build, pair testing
Project MySite contact page

Essential Question

From the Year 1 curriculum map
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.

Curriculum Map Alignment

Verbatim from Yr 1 curriculum

Concept / Knowledge / Content: Web Tools

  • Compare and contrast client-side and server-side technologies
  • Identify technologies to enhance user experience

Use of CSS

  • Use CSS to enhance the appearance and functionality of an HTML form

Projects & Activities

  • Client Managed Business Web Project: Contact Forms

Skills / Tasks

Demonstrates understanding in:

Web Construction Website Planning & Construction Incorporating Design Elements Code Type via Syntax
Previews Unit 4: the Yr 1 map lists form handling under Unit 4, Form Usage: “Create an accessible form using common elements: form, fieldset, legend, textarea, select, option, button, and input”; “Use labels with form elements”; “Compare and contrast the GET and POST methods for form handling”; “Connect an HTML form to a server-side script for processing.” This lesson introduces them in Unit 3 to complete the working contact form required by the My First Website project.
  • Standard 1 Fundamentals of HTML5
    • Obj 1 Use advanced HTML5 elements to create a website

Program Connections

Skills & Portrait alignment

Program Skills: What I’m Building Toward

Hands-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

NYS Portrait of a Graduate

Effective Communicator Critical Thinker Academically Prepared

Guaranteed & Viable Curriculum Framework

3 Dimensions for this lesson

Integrated Academic Knowledge

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.

Employability Skills

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.

Technical Skills

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].

Learning Intention

“Unwrapped” from the standard

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.

Success Criteria

  • I can group form fields with fieldset and legend, and connect every label to its field with for and id.
  • I can build a form with text, email, select, and textarea fields and decide which ones are required.
  • I can style a form with CSS so it is easy to read and use.
  • I can explain the difference between GET and POST, and why a contact form uses POST.
  • I can build a WebDNA page that sends the form as an email with [sendmail].
  • I can explain why the browser’s required is not enough on its own.

Authenticity Continuum

Where this lesson sits today
Instruction & Skill Practice
Teacher-Designed Simulation
Realistic Industry Task
Authentic Audience / Client
Product, Service, Impact, Solution

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.”

Materials & Prep

  • Students’ MySite with vars.inc (pathvar, cssvar, incvar, imgvar) and the three includes working (previous lesson), plus a contact/ page
  • Sublime Text, CyberDuck, Chrome
  • Student Walkthrough (y1-u3-l6-so)
  • Teacher prep (important): confirm that the server hosting student sites can send mail, and decide the From address students put in fromvar. 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.
  • Teacher prep: each student needs an email address they can check in class for emailvar (where their messages arrive).
  • Teacher prep: send yourself one test message through a finished form before class.

How It Works

Form to inbox
1. Browser The visitor fills in the form. required stops them if a starred field is empty.
→
2. Sent to the server Submit sends every field’s name and value to contact/send.html using POST.
→
3. WebDNA checks send.html runs [sendmail] with the answers.
→
4. Results The email arrives in the student’s inbox; the visitor sees a Thanks page.
GETPOST
Where the data travelsIn the address bar: send.html?c_name=Jordan&c_comments=...Inside the request, out of sight
Saved in history and bookmarksYes, with all the answersNo
Best forSearches and filters you might want to bookmarkAnything 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.

Day 1: The Form

HTML & CSS

The form goes in the bodycopy of contact/index.html, under the page’s usual top lines.

contact/index.html: top of page (unchanged pattern)
[include file=/citi/coding/2027/1/YOURINTS/mysite/includes/vars.inc] [text]titlevar=Contact[/text] [include file=[incvar]header.inc] [include file=[incvar]nav.inc]
contact/index.html: inside col-right
<h2>Contact Me</h2> <p>Fields marked <span class="req">*</span> are required.</p> <form class="contact-form" action="[pathvar]contact/send.html" method="post"> <fieldset> <legend>About You</legend> <label for="c_name">Name <span class="req">*</span></label> <input type="text" id="c_name" name="c_name" required> <label for="c_email">Email <span class="req">*</span></label> <input type="email" id="c_email" name="c_email" required> <label for="c_phone">Phone (optional)</label> <input type="tel" id="c_phone" name="c_phone"> </fieldset> <fieldset> <legend>Your Message</legend> <label for="c_type">Type of contact <span class="req">*</span></label> <select id="c_type" name="c_type" required> <option value="">-- Choose one --</option> <option value="Question">Question</option> <option value="Feedback">Feedback</option> <option value="Bug Report">Bug Report</option> <option value="Request">Request</option> <option value="Other">Other</option> </select> <label for="c_comments">Comments <span class="req">*</span></label> <textarea id="c_comments" name="c_comments" rows="6" required></textarea> </fieldset> <input type="hidden" name="c_send" value="yes"> <button type="submit">Send Message</button> </form>

Groups: fieldset & legend

fieldset draws a box around related fields; legend is its title. Screen readers announce the legend with each field inside it (“About You, Name”).

Labels: for = id

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.

name is what the server gets

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.

Required vs. optional

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.

Input types

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.

Hidden field: c_send

<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 & select

textarea is a multi-line box (rows sets its starting height). select is a drop-down; each option’s value is what gets sent.

css/style.css: add to the bottom
/* ===== Contact form ===== */ .req { color: #d01012; /* red star for required fields */ } .contact-form fieldset { border: 2px solid #333; /* box around each group of fields */ border-radius: 8px; /* rounded corners */ padding: 16px 20px; /* space inside the box */ margin-bottom: 20px; /* space between the two groups */ } .contact-form legend { font-weight: bold; padding: 0 8px; /* space on each side of the group title */ } .contact-form label { display: block; /* each label on its own line */ margin-top: 12px; font-weight: bold; } .contact-form input, .contact-form select, .contact-form textarea { display: block; /* each box on its own line, under its label */ width: 100%; max-width: 500px; /* never wider than 500px */ padding: 8px; /* space inside the box */ font-size: 18px; font-family: inherit; /* use the page's font, not the browser's */ border: 2px solid #999; border-radius: 6px; } .contact-form input:focus, .contact-form select:focus, .contact-form textarea:focus { border-color: green; /* highlight the box you are typing in */ outline: none; /* the green border replaces the default outline */ } .contact-form button { padding: 12px 28px; font-size: 20px; background-color: green; color: white; border: none; border-radius: 6px; cursor: pointer; /* hand cursor, so it looks clickable */ } .contact-form button:hover { background-color: #1b5e20; /* darker green under the mouse */ }

Day 2: Sending It

WebDNA [sendmail]

Two new settings go in vars.inc, and one new page, contact/send.html, receives the form and sends the email.

includes/vars.inc: add at the bottom
[!] contact form settings [/!] [text]emailvar=YOUR-EMAIL-ADDRESS[/text] [text]fromvar=ADDRESS-FROM-YOUR-TEACHER[/text]

emailvar is where messages arrive (the student’s own address). fromvar is the address the teacher provides (see Materials & Prep).

contact/send.html (new page)
[include file=/citi/coding/2027/1/YOURINTS/mysite/includes/vars.inc] [text]titlevar=Message Sent[/text] [!] Send the form as an email. This runs every time this page loads. [/!] [sendmail to=[emailvar]&from=[fromvar]&subject=MySite Contact Form] New message from the MySite contact form. Name: [c_name] Email: [c_email] Phone: [c_phone] Type: [c_type] Comments: [c_comments] -- Sent [date format=%B %d, %Y] at [time format=%I:%M %p] from IP [ipaddress] [/sendmail] [include file=[incvar]header.inc] [include file=[incvar]nav.inc] <div class="bodycopy"> <div class="col-left"> <img src="[imgvar]mail.jpg" alt="an envelope"> </div> <div class="col-right"> <h2>Thanks!</h2> <p>Your message was sent. I will get back to you soon.</p> <p><a href="[pathvar]">Back to the home page</a></p> </div> </div> [include file=[incvar]footer.inc]

What send.html does

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.

What arrives in the inbox (example)
From: (the address in fromvar) To: (your address in emailvar) Subject: MySite Contact Form New message from the MySite contact form. Name: Jordan Diaz Email: jordan@example.com Phone: Type: Feedback Comments: I like your Photos page! -- Sent October 08, 2026 at 10:15 AM from IP 10.0.0.25

The Tricky Parts

Break it on purpose

The server-side results below were tested on our WebDNA server (without sending mail). Each has a Break It experiment on the walkthrough.

1The browser’s required is not a lock

required 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.

2GET puts everything in the address bar

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.

3A field with no name is never sent

A 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].

4Labels that aren’t connected

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.

5[sendmail] runs every time its page runs

WebDNA 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.

6Keep form data out of the [sendmail] settings

Put 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.

Teacher Watch List

MySite integration
  • Check every [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.
  • Nothing arrives? Check in order: the Thanks page appeared (if not, the form’s action path is wrong); emailvar is spelled right; the spam folder; then the From address (Materials & Prep).
  • Field names must match exactly between the form’s name attributes and send.html. A mismatch shows up in the email as the field’s name in brackets.
  • send.html shows its own Thanks page. It uses the normal includes, so it should look like the rest of MySite. Students swap mail.jpg for one of their own images.
  • Refresh = resend, and every visit sends. Reloading the Thanks page or opening send.html directly sends another email. Warn students before testing so inboxes don’t fill with duplicates.
  • Spam: any public form can attract bots, and this version sends on every visit. The follow-up lesson’s server-side checks are the fix.

Lesson Flow

Two periods, ~55 min each

Day 1Build and style the form

TimePhaseWhat happens
5 minWarm-Up / HookShow 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 minDirect InstructionBuild 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 minGuided PracticeStudents add the form to contact/index.html (walkthrough Part B) and test required by submitting with fields empty.
10 minIndependent PracticeStudents add the form CSS to style.css (Part C) and adjust colors to match their site.
5 minCheck-InPairs test each other’s forms by keyboard only (Tab through every field). Preview Day 2: “Right now Submit goes nowhere.”

Day 2Send it with WebDNA

TimePhaseWhat happens
5 minWarm-Up“Where do the answers go when you click Send?” Collect guesses, then walk the How It Works flow.
15 minDirect InstructionGET 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 minGuided PracticeStudents 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 minBreak ItPairs run Break It experiments 1 through 4, predicting first. Confirm the email for a full form arrived with date, time, and IP.
5 minExit TicketCliffhanger: 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.

Assessment

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.