Forms Flashcards
What is the purpose of the HTML <form>
element?
It provides interactive controls for user data input and submission, validates user input, and sends data to a server.
What does the action
attribute of the <form>
element specify?
The URL where the form data is sent, containing name/value pairs of form controls.
What are the two common HTTP methods for form submission, and how do they differ?
GET
sends data as a query string in the URL, while POST
sends data in the HTTP request body, making it more secure for sensitive data.
What does the method="POST"
attribute do in a form submission?
It sends form data in the HTTP request body, which is more secure for sensitive data like passwords.
What is the purpose of the name
attribute in form controls?
It identifies form controls and helps with server-side data processing.
How do radio buttons behave in a form?
They share the same name
attribute, ensuring only one button in a group is selected, and the selected button’s name=value
pair is submitted.
How do checkboxes behave in a form?
They can share the same name
, and only selected checkboxes are submitted with their name
and value
.
What is the purpose of the for attribute in <label> elements?</label>
It associates the label with a form control by matching the control’s id, improving accessibility.
What does the capture
attribute do in a file input field?
It allows the use of the device’s camera or microphone to capture media, with options for front (capture="user"
) or back (capture="environment"
) devices.
How does the pattern
attribute in form inputs work?
It specifies a regular expression (regex) that input must match for validation.
What does the type="file"
input allow users to do?
It allows users to upload files, with restrictions based on the accept
attribute (e.g., images only).
How does the input type affect the mobile keyboard appearance?
Input types like tel
and email
change the keyboard layout to be optimized for their respective data (e.g., number keypad for phone numbers, email keyboard with @
and .
).