HTML Forms
The <form> element collects user input and sends it to a server for processing, wrapping input fields, buttons, and other controls together.
The action attribute specifies where to send the data, and the method attribute (GET or POST) specifies how. Forms are essential for logins, searches, surveys, and virtually any interactive site feature.
<form action="/submit" method="post">...</form>action and method
action defines the URL that receives submitted data. method="get" appends data to the URL (visible, for searches); method="post" sends data in the request body (better for sensitive or large data).
Form submission
A <button type="submit"> or <input type="submit"> triggers form submission, gathering all named fields' values and sending them per the action/method.
<form action="/search" method="get">
<input type="text" name="q">
<button type="submit">Search</button>
</form>(submits to /search?q=value)GET appends form field values as URL query parameters.
<form action="/login" method="post">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">Log In</button>
</form>(submits username/password securely in the request body)POST hides submitted data from the URL, more suitable for sensitive fields.
Key points
- <form> wraps input controls that collect user data.
- action specifies the URL to submit data to.
- method (GET or POST) specifies how data is sent.
- Every meaningful field needs a name attribute to be submitted.
