Complete the code to create a form element.
<[1] action="/submit" method="post"> <label for="name">Name:</label> <input type="text" id="name" name="name"> </[1]>
The form tag defines a form in HTML. It groups input elements and allows data submission.
Complete the code to add a submit button inside the form.
<form action="/submit" method="post"> <input type="text" name="email" aria-label="Email address"> <button type="[1]">Send</button> </form>
type="button" which does not submit the form.type="reset" which clears the form inputs.The submit type on a button sends the form data to the server when clicked.
Fix the error in the input field to make it accessible by linking label and input.
<label for="[1]">Username:</label> <input type="text" id="username" name="username">
for and input's id.id attribute on the input.The for attribute in the label must match the id of the input to connect them for accessibility.
Fill both blanks to create a text input with a placeholder and required attribute.
<input type="[1]" name="email" placeholder="[2]" required>
email type but placeholder says 'Enter your name'.The input type should be text for general text input. The placeholder shows a hint inside the input box.
Fill all three blanks to create a form with a label, input, and submit button.
<form action="[1]" method="[2]"> <label for="user">[3]</label> <input type="text" id="user" name="user"> <button type="submit">Send</button> </form>
get method when post is expected.The action attribute sets the URL to send data. The method is usually post for sending data securely. The label text describes the input.
Practice
<form> element in HTML?Solution
Step 1: Understand the role of the <form> tag
The <form> element groups input fields and buttons to collect user data.Step 2: Identify the purpose of forms
Forms send collected data to a server for processing, like login or signup.Final Answer:
To collect user input and send it to a server -> Option DQuick Check:
Form = collect and send data [OK]
- Confusing forms with layout elements
- Thinking forms style content
- Assuming forms display images
<form> tag specifies where the form data is sent?Solution
Step 1: Identify the purpose of the 'action' attribute
The 'action' attribute defines the URL where form data is sent after submission.Step 2: Differentiate from other attributes
'method' defines how data is sent (GET or POST), 'type' and 'name' are not for destination.Final Answer:
action -> Option CQuick Check:
action = destination URL [OK]
- Confusing 'method' with 'action'
- Using 'type' instead of 'action'
- Omitting the 'action' attribute
<form action='/submit' method='post'> <input type='text' name='username' /> <button type='submit'>Send</button> </form>
Solution
Step 1: Analyze the form attributes
The form uses 'action="/submit"' and 'method="post"', so data goes to '/submit' via POST.Step 2: Understand form submission behavior
On clicking the submit button, the browser sends the input data as POST to the specified URL.Final Answer:
The browser sends the username data to '/submit' using POST method -> Option AQuick Check:
action + method = POST to /submit [OK]
- Assuming GET method when POST is set
- Thinking JavaScript handles submission automatically
- Believing page reloads without sending data
<form action='/send' method='post'> <input type='text' name='email'> <button type='submit'>Submit</button> </form>
Solution
Step 1: Check input tag syntax
The input tag is <input type='text' name='email'> without self-closing slash.Step 2: Understand HTML5 input tag rules
In HTML5, void elements like input do not require a closing tag or slash; both <input ...> and <input ... /> are valid.Step 3: Verify other elements
Form has action and method; button is type='submit'. No errors present.Final Answer:
There is no error in the code -> Option BQuick Check:
Void tags like input don't need closing slash in HTML5 [OK]
- Thinking input must always have a closing slash
- Confusing button types
- Missing method attribute (actually present)
Solution
Step 1: Check the form's action attribute
The form must send data to '/register', so action='/register' is required.Step 2: Verify the method attribute
The method should be 'get' to send data via URL parameters.Step 3: Confirm input and button correctness
The input has name='name' and the button is type='submit', which is correct.Final Answer:
Form with action='/register' and method='get' -> Option AQuick Check:
action='/register' + method='get' = <form action='/register' method='get'> <input type='text' name='name' /> <button type='submit'>Register</button> </form> [OK]
- Omitting action attribute
- Using wrong method (post instead of get)
- Missing submit button type
Ready to prove it?
Pass the test and this pattern moves unknown
