HTML Forms and Input Types: action, method, labels, select, textarea and button
A form's action says where the data goes and its method says how it travels there. Work through the pieces that carry the data — name attributes, input types, labels tied to ids, select options, textarea content and the button that submits it all — then test yourself on the details that trip people up.
An HTML form is a <form> element that gathers what a user types and sends it somewhere. The action attribute says where the data goes, and the method attribute says how it gets there — get (the default) appends the data to the URL as a query string, while post puts it in the request body. Everything inside the form — <input>, <select>, <textarea>, <button> — is a control, and each control needs a name attribute or its value never leaves the page.
action, method, and enctype
The action attribute holds the URL that processes the submission. Omit it and the data is sent to the URL of the page containing the form. The method attribute accepts three values: get, post, and dialog — that last one closes a surrounding <dialog> and fires a submit event instead of sending anything. With get, the browser builds a query string such as search.php?q=html&sort=new and sends an empty request body. That is fine for a search you want to bookmark or share, and genuinely bad for a password, because the value sits in the address bar, in browser history, and in server logs. With post, the data travels in the request body instead, which is what you want for anything private, anything large, and anything that changes data on the server. One more attribute matters as soon as you accept files: enctype controls how a post body is encoded. It defaults to application/x-www-form-urlencoded, and it must be set to multipart/form-data when the form contains a file input.
Why every control needs a name
Form data is a list of name=value pairs. The browser walks the form, reads each control's name and current value, and sends the pairs. A control with no name is silently skipped — so is a disabled control, and so is an unchecked checkbox or radio button. This is where name and id get tangled: name is for the server, while id is for the page, used by CSS, by JavaScript, and by a label's for attribute. Radio buttons are a special case: sharing one name across several radios is exactly what makes them mutually exclusive.
Picking an input type
The type attribute on <input> changes both the control you see and the rules the browser enforces. The full set is text, password, email, tel, url, search, number, range, date, time, datetime-local, month, week, color, file, checkbox, radio, hidden, submit, reset, button, and image. Choosing well buys you built-in validation — a value with no @ in an email field blocks submission and shows a browser message — and a better mobile keyboard. If you misspell the type or leave it off entirely, the browser quietly uses text instead.
Labels, select, textarea, and button
A <label>'s for attribute must match the control's id, not its name. That pairing lets a screen reader announce the label when focus lands on the field, and it makes the label text a clickable target. A <select> wraps <option> elements; each option's value is what gets submitted, an option with no value submits its own text content instead, and adding multiple lets the user pick several. A <textarea> takes its starting text from between its tags, because HTML gives it no value attribute at all. And a <button> associated with a form defaults to type="submit" — a detail worth remembering. Ready to practice? Try the D276 practice sets or review the full Web Development Foundations study guide.
Practice: Forms And Input Types
-
In this markup, what value must the label's for attribute contain? <label for="???">Email address</label> <input type="email" id="user-email" name="email">
- email, because for must match the control's name
- email, because for must match the control's type
- user-email, because for must match the control's id
- input, because for must name the element being labeled
Show answer & explanation
Correct answer: user-email, because for must match the control's id. The for attribute takes the id of a labelable form control in the same document, so it must be "user-email". Matching the name is the tempting wrong answer because name and id often hold the same string in real code — but name exists to label the data for the server, while id is the page-level hook that for, CSS, and JavaScript all use. If for and id do not match, the label stops announcing to screen readers and clicking it no longer focuses the field.
-
A form is written as <form action="/signup"> with no method attribute. The user fills in two text fields and submits. What does the browser do?
- It uses GET and appends the field data to /signup as a query string
- It uses POST and sends the field data in the request body
- It uses GET but sends the field data in the request body
- It refuses to submit, because method is a required attribute
Show answer & explanation
Correct answer: It uses GET and appends the field data to /signup as a query string. When method is absent, the browser uses GET, which appends the name/value pairs to the action URL after a ? — so the user lands on something like /signup?first=Ada&last=Lovelace. POST is the most tempting distractor because sign-up forms should use POST, but "should" is not "does": you have to write method="post" to get it. The option pairing GET with a request body is also out, because a GET form submission sends an empty body.
-
Given this form, what happens when the user clicks the Cancel button? <form action="/save" method="post"> <input type="text" name="title"> <button>Cancel</button> </form>
- Nothing happens, because a button does nothing without JavaScript
- It submits the form to /save, because a button's type defaults to submit
- It clears the title field, because a button defaults to type="reset"
- Nothing happens, because a button must be inside a fieldset to submit
Show answer & explanation
Correct answer: It submits the form to /save, because a button's type defaults to submit. A <button> associated with a form defaults to type="submit" — that is also what you get if type is empty or invalid — so this "Cancel" button posts the form, almost certainly not what the author intended. The "nothing happens" option describes type="button", which is the behavior you get only when you write it explicitly. Any button that should not submit needs type="button", and a real reset needs type="reset".
-
A developer writes <input type="quantity" name="qty"> because they want a quantity field. What actually renders in the browser?
- Nothing renders, because the browser discards invalid elements
- A number spinner, because the browser matches the closest valid type
- A text field that the browser refuses to submit until type is fixed
- A single-line text field, because an unknown type falls back to text
Show answer & explanation
Correct answer: A single-line text field, because an unknown type falls back to text. There is no quantity input type, and an input whose type is omitted or set to an unknown value is rendered as type="text" — an ordinary text box that submits normally. That silent fallback is exactly why the mistake survives testing: the page looks fine, but the numeric keyboard, spinner, and min/max validation you expected from type="number" never appear. Browsers do not guess at a "closest" type.
-
This select sits in a form that the user submits without touching the dropdown. What name/value pair is sent? <select name="color"> <option>Sky Blue</option> <option value="grn">Green</option> </select>
- color=grn
- color=on
- color=Sky Blue
- Nothing, because the first option has no value attribute
Show answer & explanation
Correct answer: color=Sky Blue. Two rules combine here: in a single-selection dropdown where no option carries the selected attribute, the first selectable option is chosen by default, and an option with no value attribute submits its text content instead. So the browser sends color=Sky Blue, with the space encoded in transit. The "nothing is sent" option is the tempting one, but a missing value attribute is a fallback, not a disqualification — and the value "on" belongs to checkboxes and radios that omit value, not to options.
-
You are adding <input type="file" name="resume"> to a form so users can upload a document. What must the <form> tag specify for the file's contents to reach the server?
- method="post" and nothing else, since post handles files automatically
- method="post" together with enctype="multipart/form-data"
- method="get" together with enctype="multipart/form-data"
- method="post" together with accept="application/pdf" on the form
Show answer & explanation
Correct answer: method="post" together with enctype="multipart/form-data". File uploads need both pieces: POST, because file content cannot be put in URL parameters, and enctype="multipart/form-data", which splits the submission into parts so binary content survives. The "post and nothing else" option is the common trap — POST alone still uses the default application/x-www-form-urlencoded encoding, which sends only the file's name, not its bytes. A GET submission puts everything in the URL and sends an empty body, so enctype has nothing to encode there, and accept is an input attribute that merely hints at file types in the picker.
A worked example
Here is a small form that uses each piece correctly. Read it once, then read the notes underneath.
<form action="/contact" method="post">
<label for="name">Full name</label>
<input type="text" id="name" name="name" required>
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<label for="topic">Topic</label>
<select id="topic" name="topic" required>
<option value="">Choose one</option>
<option value="billing">Billing</option>
<option value="tech">Technical</option>
</select>
<label for="msg">Message</label>
<textarea id="msg" name="message" rows="6"></textarea>
<button type="submit">Send</button>
</form>
Every control has a name for the server and an id for its label. The first option carries value="", which makes it a placeholder: because it is selected by default and its value is empty, required on the <select> forces the user to make a real choice. The textarea is empty because there is nothing between its tags, and rows="6" overrides the default of 2 rows — writing value="" on a textarea would do nothing at all, since that attribute does not exist for it in HTML.
Mistakes people actually make
- Pointing
forat the name. Iffor="email"but the input'sidisuser-email, the label is decorative: clicking it does not focus the field and assistive tech reports an unlabeled input. - Using
placeholderas the label. Placeholder text vanishes the moment someone types, leaving them with no idea what the field wanted. Keep a real<label>and treat the placeholder as an example value. - Giving radio buttons different names. Radios form one mutually exclusive group only when they share a
name. With different names each radio is its own group, so several can end up checked at once and clicking one never clears another. - Forgetting
valueon checkboxes and radios. With novalue, a checked control submits the literal stringon— technically valid, practically useless. - Uploading without
enctype. A file input inside a plainpostform sends only the file's name, because the default urlencoded format cannot carry binary content. - Assuming a bare
<button>is inert. It submits. Addtype="button"to anything that should not.
Reasoning through the tricky cases
When you are unsure whether a value will be submitted, ask three questions in order: does the control have a name, is it enabled, and does it have a value to report? That sequence explains most surprises. It clarifies why readonly and disabled behave differently — a readonly text field or textarea cannot be edited but is still submitted, while a disabled control is excluded from the data entirely and cannot take focus. It explains why an unchecked checkbox produces no pair at all rather than an empty one, and why a whole radio group disappears from the data when nothing is selected. For the exact attribute lists, the MDN reference for <input> is the source worth bookmarking.
Want someone to walk you through this?
Book 1-on-1 prep for WGU D276 — original coaching, never exam content.
Stuck on this topic? WhatsApp us on +1 646 980 4914.
Working through the whole course? Read the full WGU D276 study guide, or see every WGU D276 practice topic.