- The problem: a page that shows but cannot receive
- The form tag, action and method
- The essential input types
- label: connecting a caption to its field
- textarea, select, radio and checkbox
- Built-in validation without JavaScript
- Build the full order form
- See the result yourself
- The form on mobile
- Validate your code
- Common form mistakes
- Wrap-up and what is next
- FAQ
- 🔗 Official sources
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 writeaction="#"for now so you can see the result yourself without a server.method: the sending method.getputs the data in the address bar (great for learning, testing and on-site search), whilepostsends it hidden in the request body (use it later for real orders and passwords once a server receives them).
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 setminandmax.date: a ready-made date picker from the browser.password: masks what is typed with dots.checkboxandradio: 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 samenamevalue 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"andtype="number": automatic format checks.minandmax: limits for numbers and dates.minlengthandmaxlength: limits for text length.pattern: a custom regular expression, such as an Egyptian mobile number:pattern="01[0-9]{9}"
7. Build the full order form
Now we combine everything into an order form for the shop page from part 3. Follow the steps:
- Open
index.htmland place this code right before the closing</main>tag. - Save the file and open it in the browser (or via Live Server).
- Leave a required field empty and press "Send order" to see the browser's validation message.
- 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:

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:

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:

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
- Forgetting the
nameattribute on fields: without it the field's value is never sent, even if the visitor fills it in. - Using
placeholderinstead oflabel: a placeholder disappears while typing and is not reliably read by screen readers; it is a hint, not a caption. - A
forvalue that does not match the field'sid, which silently breaks the binding with no error message. - Sending passwords or sensitive data with
method="get", which stores them in the browser history and server logs. - 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
- MDN: Web Forms tutorials
- MDN: the input element and all its types
- MDN: the form element and its attributes
- web.dev: Learn Forms (Google's official course)
- W3C Markup Validator
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.
Comments (0)
No comments yet. Be the first to comment!
Add Your Comment