The form element, online
Six activities your students do on their own devices. See who's finished, and their scores.
The form element in one minute
What students need to know
action="/register" tells the browser to send the form data to /register. Without action, data goes to the current page. The input and button are both inside the <form> element. Only controls inside the form are included in the submission.
action holds the destination URL for the form submission. href is used on <a> links, not forms. POST sends data in the request body - safer for passwords and large data. GET appends it to the URL.
Mistakes students make
- HTML tag names must be lowercase. <FORM> should be written as <form>.
- Attributes must be written inside the opening tag, not on a separate line. The method attribute belongs in the <form> opening tag: <form action="/login" method="post">.
- Attribute values must be in double quotes: type="submit", not type=submit without quotes.
- The </form> closing tag appears before the button element. The button must be inside the form: move </form> after the button.
What students will learn in this module
Every question in Module 26
Quick questions
- Which attribute on <form> specifies where the data is sent?AactionBhref
- What does method="post" do?AAppends data to the URL as query parametersBSends data in the HTTP request body
- True or false: forms can be nested inside other forms.AFalseBTrue
- True or false: <FORM> with capital letters is valid HTML.ATrueBFalse
- Which method is most appropriate for a search form?AgetBpost
Key terms
Students type the meaning of:
action
Match the pairs
<form action="/login" method="post"> <button>Login</button> </form>Match it to what it does
<form action="/search" method="get"> <input type="text" name="q"> <button>Search</button> </form>Match it to what it does
action specifies the URL where form data is sent on submissionMatch it to what it doesAll form controls must be inside <form> - inputs outside the form are not submittedMatch it to what it does<FORM action="/go" method="post"> <button>Go</button> </FORM>Match it to what it does
<form action=/submit method="post"> <button>Submit</button> </form>Match it to what it does
Fill in the blanks
<___ action="/submit" method="post"> <button>Send</button> </form>
Hint: Type the element name that creates a form container
<form ___="/login" method="post"> <button>Login</button> </form>
Hint: Type the attribute that specifies where the form data is sent
<form action="/save" ___="post"> <button>Save</button> </form>
Hint: Type the attribute that specifies how form data is sent to the server
<form action="/send" method="___"> <button>Submit</button> </form>
Hint: Type the method value that sends form data in the HTTP request body
<form action="/search" method="get"> <button>Search</button> </___>
Hint: Type the element name for the closing tag that ends the form
Spot the error
Question 1
A<FORM action="/submit" method="post">B <input type="text" name="name">C <button>Submit</button>D</form>
Question 2
A<form action="/login">B method="post"C <input type="text" name="user">D <button>Login</button>E</form>
Question 3
A<form action="/search" method="get">B <input type="text" name="q">C <button type=submit>Search</button>D</form>
Question 4
A<form action="/register">B <input type="email" name="email">C <input type="password" name="pass">D </form>E <button>Register</button>
Question 5
A<form>B <input type="text" name="city">C <input type="text" name="state">D <input type="text" name="zip">E <Button>Submit</Button>F</form>
