CHAPTER 37 · HTML

Guided project: a workshop request form

Build a form in clear steps. Turn requirements into labelled controls, then test missing answers and submitted values.

Download example files (ZIP)

The project brief

Imagine a college study club wants a draft request screen. It needs a practice alias, a topic, between one and three sessions, one time choice and an optional question. A reminder flag is optional. A requirement is something the finished work must do. Write requirements before choosing tags.

We are building an HTML entry screen and inspecting a local submission URL. We are not building registration, email, a database or a booking service. Use invented information because GET values appear in the address bar.

Step 1: plan each answer

Use text for an alias, select for a short fixed list, number for a count, radios for one time choice, textarea for a longer question and checkbox for an independent flag. Give every control a label. Mark required and optional answers visibly.

Plan the receiving names: alias, topic, count, slot, question and reminder. Id connects a label to a control. Name identifies a submitted entry. Two time radios share name=slot but have different ids and values.

Step 2: save the smallest working version

Create a folder and put form-result.html from Chapter 31 inside it. Add workshop-form-start.html. Start with the alias, topic and button. Opening the result page proves only that navigation worked. Inspect the URL to see the practice values. The static page does not read or save them.

Test the empty form first, then choose an alias and topic. Fix this small version before adding more fields. This makes it easier to find which change caused a problem.

Step 3: add related groups

The complete version uses fieldset and legend to explain the request group and the time group. A shared radio name permits one selected time. Required on one radio applies to the group. Required on a checkbox would demand that specific checkbox; our optional reminder should not be required.

Choose a different id for every control. A label for morning must match id=morning, not name=slot. Click each label to check the connection.

Step 4: match rules to the brief

The count uses min=1, max=3 and step=1 because half a session is not allowed here. The first topic option has an empty value, so required asks the learner to choose an actual topic. Maxlength=200 bounds the question; an empty answer is allowed. These are exercise rules, not universal workshop rules.

State the count limits before the field and connect that instruction with aria-describedby. Browser messages vary. A real receiving service must repeat appropriate checks.

Step 5: test more than a successful entry

A test case is one input situation with an expected result. Try an empty alias, no topic, no radio, count 0, count 4 and count 1.5. Each unsuitable required or numeric answer should block ordinary validated submission in saved files. Then try alias Learner, topic Forms, count 2 and Afternoon.

Submit with the reminder checked, then unchecked. The checked version includes reminder=yes; the unchecked version omits it. An empty optional textarea can still submit an empty named value. Not every unanswered control is omitted.

Step 6: explain the result honestly

A query string is the part after the question mark in a URL. Browsers encode characters when building it; a plus can represent a space in these form query values. Check names and values rather than relying on their order.

No page here sends a reminder or knows whether a room has space. Those jobs need receiving logic. The embedded preview deliberately blocks submission; save the files locally for the full test.

Follow the idea

Build and test in small steps
  1. 1Write the requirements
  2. 2Choose labelled controls and names
  3. 3Add matching constraints
  4. 4Test valid, invalid and omitted values

The local result page demonstrates a URL, not a real registration.

Complete program: workshop-form-start.html

Save this as workshop-form-start.html. Open it in your browser.

workshop-form-start.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Workshop Form First Step</title>
  </head>
  <body>
    <h1>Plan a fictional workshop request</h1>
    <p>This is a local form exercise, not a booking. Keep form-result.html beside this file.</p>
    <form action="form-result.html" method="get">
      <p>
        <label for="practice-alias">Practice alias (required)</label>
        <input type="text" id="practice-alias" name="alias" required maxlength="30" />
      </p>
      <p>
        <label for="topic">Topic (required)</label>
        <select id="topic" name="topic" required>
          <option value="">Choose a topic</option>
          <option value="links">Links</option>
          <option value="forms">Forms</option>
        </select>
      </p>
      <button type="submit">Inspect the practice request</button>
    </form>
  </body>
</html>
Browser previewDocument title: Workshop Form First Step

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.

Expected result: two required answers and a button. Blank required answers block ordinary validated submission. Valid fictional answers navigate to the local result page with alias and topic entries.

Complete program: workshop-form-complete.html

Save this as workshop-form-complete.html. Open it in your browser.

workshop-form-complete.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Workshop Form Complete Practice</title>
  </head>
  <body>
    <h1>Prepare a fictional workshop request</h1>
    <p>
      No place is reserved and no data is stored. Use made-up details and keep form-result.html
      beside this file.
    </p>
    <form action="form-result.html" method="get">
      <fieldset>
        <legend>Your practice request</legend>
        <p>
          <label for="alias">Practice alias (required)</label>
          <input type="text" id="alias" name="alias" required maxlength="30" />
        </p>
        <p>
          <label for="topic">Topic (required)</label>
          <select id="topic" name="topic" required>
            <option value="">Choose a topic</option>
            <option value="links">Links</option>
            <option value="forms">Forms</option>
          </select>
        </p>
        <p id="count-help">Choose 1, 2 or 3 practice sessions.</p>
        <p>
          <label for="count">Session count (required)</label>
          <input
            type="number"
            id="count"
            name="count"
            min="1"
            max="3"
            step="1"
            required
            aria-describedby="count-help"
          />
        </p>
      </fieldset>
      <fieldset>
        <legend>Choose one time (required)</legend>
        <p>
          <input type="radio" id="morning" name="slot" value="morning" required />
          <label for="morning">Morning</label>
        </p>
        <p>
          <input type="radio" id="afternoon" name="slot" value="afternoon" />
          <label for="afternoon">Afternoon</label>
        </p>
      </fieldset>
      <p><label for="question">One practice question (optional, up to 200 characters)</label></p>
      <p><textarea id="question" name="question" rows="3" cols="28" maxlength="200"></textarea></p>
      <p>
        <input type="checkbox" id="reminder" name="reminder" value="yes" />
        <label for="reminder">Include a practice reminder flag</label>
      </p>
      <button type="submit">Inspect the practice request</button>
    </form>
  </body>
</html>
Browser previewDocument title: Workshop Form Complete Practice

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.

Expected result: grouped questions, labels and an explicit practice button. Valid answers create a URL containing named values. Reminder appears only when checked. This is not a booking confirmation.

Problem and solution

Problem: clicking Morning changes an unrelated field.

Solution: inspect duplicate ids and label for values. Keep ids unique and share a name only for related radio choices. Click every label before calling the form finished.

Common mistakes and useful tips

  • Do not nest forms.
  • Use invented information in this GET exercise.
  • Do not claim the result sends reminders.
  • Do not replace labels with placeholders.
  • Test invalid answers, keyboard focus and omitted values.

Practice questions

  1. Why plan fields before tags?
  2. Which name is shared by the time choices?
  3. Why is the first topic value empty?
  4. What should happen with count=1.5?
  5. What is sent for an unchecked reminder?
  6. Build the complete example and run valid and invalid cases. Was a booking made?
Check your practice answers
  1. So every control serves a stated requirement.
  2. Slot. Their ids and values differ.
  3. Required rejects that empty selection and asks for a real choice.
  4. It fails the whole-session step rule.
  5. No reminder entry.
  6. Invalid constrained values block ordinary submission. Valid values reach a static page; no booking, storage or email occurs.

Interview questions

How do you choose a control?

Start with the question and allowed answers, then choose the control, label and constraints that match.

Why test names as well as appearance?

A field can look correct but omit its answer if name is missing. The receiver needs agreed names and values.

Why distinguish optional and required?

Unnecessary required answers block readers. Missing required rules can accept incomplete requests. Follow the actual task.

Does a working form prove a service is complete?

No. It demonstrates entry and submission. Receiving logic, trusted checks, storage and promised follow-up are separate work.

Quick revision

  • Plan requirements and names.
  • Build a small version first.
  • Test valid, invalid and omitted values.
  • Describe the actual result.