Build Your Website from Scratch (4): HTML Forms and Inputs — Receive Your First Visitor Data

Build a complete order form: text, phone, email, dropdown, radio and notes fields with automatic validation and no JavaScript, and watch your data actually submit.

Build Your Website from Scratch (4): HTML Forms and Inputs — Receive Your First Visitor Data
Build a complete order form: text, phone, email, dropdown, radio and notes fields with automatic validation and no JavaScript, and watch your data actually submit.

Build Your Website from Scratch (4): HTML Forms and Inputs — Receive Your First Visitor Data

Share:
⏱ 6 min read🔄 Last updated: 2026-12-03✍ NOOR 4 TECH Team

A form is how your website receives data from a visitor: their name, phone number, order.
In short: the form tag groups the fields, the input tag with its types shapes each field, and label binds a caption to every field.
In this part you build a complete working order form in the browser, with automatic input validation and not a single line of JavaScript.

In part 3 we built a full semantic shop page. But the page still only shows information; a visitor cannot contact you or order a product. Today we add a real order form: text, phone, email fields, a product list and notes, every field validating its input automatically. At the end you will see your own data actually submitted and visible in the address bar, proof that the form works.

1. The problem: a page that shows but cannot receive

Every business site needs a channel back: a contact form, an order form, a signup form. All of them are the same idea: a set of fields the visitor fills in, then presses submit, and the data travels to an address you choose. HTML provides all of this with three core tags: form which wraps the form, input with its many types for the fields, and label which gives every field a clear caption.

2. The form tag, action and method

The <form> tag has two attributes that decide what happens when the submit button is pressed:

  • action: the address the data is sent to. In our project we write action="#" for now so you can see the result yourself without a server.
  • method: the sending method. get puts the data in the address bar (great for learning, testing and on-site search), while post sends it hidden in the request body (use it later for real orders and passwords once a server receives them).
💡 Tip: start with method="get" while learning. After pressing submit, look at the address bar: your data appears there as ?name=...&phone=..., the fastest proof that the form works.

3. The essential input types

The <input> tag changes its shape and behavior based on the type value. These are the types you will use daily:

  • text: plain text such as a name.
  • email: an email address; the browser refuses to submit without an @, and opens a keyboard with @ on mobile.
  • tel: a phone number; opens a numeric keypad on mobile.
  • number: digits only, with up/down arrows, and you can set min and max.
  • date: a ready-made date picker from the browser.
  • password: masks what is typed with dots.
  • checkbox and radio: tick boxes and single-choice groups (coming shortly).
  • submit: the submit button itself.

Try this line alone in a blank page and switch type between text, email and date to see the difference:

<input type="email" name="email" placeholder="name@example.com">

4. label: connecting a caption to its field

Do not write "Name:" as loose text next to a field. Use <label> and bind it to the field by matching its for attribute with the field's id:

<label for="name">Full name</label>
<input type="text" id="name" name="name">

This binding has a real practical effect: clicking the words "Full name" moves the cursor into the field instantly (a bigger tap target on mobile), and screen readers announce the correct caption to blind users instead of a meaningless "edit text".

5. textarea, select, radio and checkbox

Four elements that complete any form:

  • <textarea>: a long text area for notes and messages.
  • <select> with <option>: a dropdown list, such as picking a product.
  • radio: one choice out of a group; give them the same name value so the choices exclude each other.
  • checkbox: independent agreements and options such as "I accept the terms".
<label for="product">Product</label>
<select id="product" name="product">
  <option value="basic">Basic plan</option>
  <option value="pro">Pro plan</option>
</select>

<input type="radio" id="pickup" name="delivery" value="pickup">
<label for="pickup">Store pickup</label>
<input type="radio" id="delivery" name="delivery" value="home">
<label for="delivery">Home delivery</label>

6. Built-in validation without JavaScript

HTML validates data before submission just by adding attributes:

  • required: the field is mandatory; the browser refuses to submit and shows a hint.
  • type="email" and type="number": automatic format checks.
  • min and max: limits for numbers and dates.
  • minlength and maxlength: limits for text length.
  • pattern: a custom regular expression, such as an Egyptian mobile number: pattern="01[0-9]{9}"
⚠️ Warning: browser validation is a convenience for the visitor, not protection. Anyone can disable it from developer tools. When you connect the form to a real server later, always repeat the same checks there.

7. Build the full order form

Now we combine everything into an order form for the shop page from part 3. Follow the steps:

  1. Open index.html and place this code right before the closing </main> tag.
  2. Save the file and open it in the browser (or via Live Server).
  3. Leave a required field empty and press "Send order" to see the browser's validation message.
  4. Fill the whole form, press submit, then look at the address bar: your data appears after the ? mark.
<section id="order">
  <h2>Order now</h2>
  <form action="#" method="get">

    <label for="name">Full name</label>
    <input type="text" id="name" name="name"
           placeholder="e.g. Ahmed Mohamed" required>

    <label for="phone">Mobile number</label>
    <input type="tel" id="phone" name="phone"
           placeholder="01xxxxxxxxx"
           pattern="01[0-9]{9}" required>

    <label for="email">Email (optional)</label>
    <input type="email" id="email" name="email"
           placeholder="name@example.com">

    <label for="product">Product</label>
    <select id="product" name="product" required>
      <option value="">— choose a product —</option>
      <option value="basic">Basic plan</option>
      <option value="pro">Pro plan</option>
    </select>

    <label for="qty">Quantity</label>
    <input type="number" id="qty" name="qty"
           min="1" max="10" value="1" required>

    <p>Delivery method:</p>
    <input type="radio" id="pickup" name="delivery" value="pickup" checked>
    <label for="pickup">Store pickup</label>
    <input type="radio" id="home" name="delivery" value="home">
    <label for="home">Home delivery</label>

    <label for="notes">Extra notes</label>
    <textarea id="notes" name="notes" rows="4"
               placeholder="Anything you want to tell us"></textarea>

    <input type="checkbox" id="agree" name="agree" required>
    <label for="agree">I accept the return and exchange policy</label>

    <button type="submit">Send order</button>
  </form>
</section>

8. See the result yourself

This is how the form looks in the browser before any styling. It is plain because we have not written CSS yet; what matters is that every field works and validates its input:

The order form as it appears in the browser: name, mobile, email fields, product dropdown, quantity, delivery method, notes and the submit button
Figure 1: the complete order form in the browser before any CSS

And after filling and submitting it with method="get", the data shows up in the address bar in this format, practical proof that the form is sound:

The form filled with test data and submitted, with the field values visible in the browser address bar after the question mark
Figure 2: after submitting, the form data appears in the address bar (method="get")

9. The form on mobile

Thanks to the <meta name="viewport"> tag we added in part 2, fields render at a proper size on mobile, and input types open the right keyboard automatically: digits for the phone field, an @ key for email:

The order form on a mobile screen: fields span the screen width and the phone field opens a numeric keypad
Figure 3: the form on mobile: the phone field opens a numeric keypad automatically

10. Validate your code

As in the previous parts: open the official W3C validator, upload your file, and confirm the message "No errors or warnings to show". The most common form mistake it catches is a missing label or a broken for/id pair.

11. Common form mistakes

  1. Forgetting the name attribute on fields: without it the field's value is never sent, even if the visitor fills it in.
  2. Using placeholder instead of label: a placeholder disappears while typing and is not reliably read by screen readers; it is a hint, not a caption.
  3. A for value that does not match the field's id, which silently breaks the binding with no error message.
  4. Sending passwords or sensitive data with method="get", which stores them in the browser history and server logs.
  5. Relying on browser validation alone, then being surprised by empty or malicious data at the server.

12. Wrap-up and what is next

Today your page received its first real visitor data: you built a complete order form with text, phone, email, a dropdown, radio buttons and notes, every field bound to a label and validating itself automatically. The form works but still looks like the browser default. In part 5 we start CSS from scratch: colors, fonts and field styling until the form and the whole page look professional and responsive.

FAQ

Does the form work without a server?

The display and validation parts work entirely in the browser. But for the data to actually reach your inbox or a database you need a server to receive it, which comes in later parts when we cover hosting. In the meantime, services like Formspree can receive submissions for you just by changing the action value.

What is the difference between id and name on a field?

id identifies the element inside the page and binds it to its label; it is not sent with the data. name is the key of the submitted data; what appears in the address bar or what the server receives. You usually need both.

Why don't my radio buttons deselect each other?

Because each button has a different name value. Group related options with the same name (like name="delivery") and the visitor can pick only one; give each button a distinct value so you know which one was chosen.

Do I need JavaScript for validation?

Not for the basics: required, type and pattern cover the common cases. You only need JavaScript for complex checks (like comparing two fields) or fully custom messages.

🔗 Official sources

Target keywords and how we picked them: "HTML form input types" and "contact form HTML" appear in Google autocomplete (evidence of real search demand; volumes unmeasured), plus the long-tail "form validation HTML" and "HTML label tag". In Arabic, "نماذج html" and "form في html" autocomplete for Egyptian users, while "نموذج اتصال html" showed no suggestions and was dropped.

⭐ Featured Recommendation

📈 Double Your Site Traffic & Revenue with Featured Backlinks & SEO

Get a pinned Featured Backlink in our directory or a complete SEO audit by NOOR 4 TECH experts to dominate rankings.

Explore Featured Package ⭐
💼 NOOR 4 TECH Professional Services

Looking for a Technical Partner for Your Next Project?

We deliver enterprise web development, mobile apps, technical SEO, and AI automation.

Author

Ibrahim Moustafa

Electronics and communications engineer, working in IT since 2004. He reviews NOOR 4 TECH articles and tests its tools himself before publication.

Comments (0)

No comments yet. Be the first to comment!

Add Your Comment

Your email will not be published. Comments require review before publishing.