[HTML] form
<form></form>
How did I encounter this?
While learning Flask, I got to use <form></form> in order to test REST API request/response.
Syntax
<form></form> is an HTML element that allows user input to be gathered and sent to a server. It consists of input fields such as text boxes or checkboxes and a submit button. When the form is submitted, the browser gathers the data from these fields and either sends it to a specified server endpoint or handles it using JavaScript.
Attributes
- action: the URL or endpoint where data gets sent.
- method: the HTTP method (usually GET or POST)
- name on the form controls (such as <inputs>)
Example
<form method="GET" action="/search">
<label for="q">Search Query:</label>
<input type="text" id="q" name="q">
<button type="submit">Search</button>
</form>
When Search button is hit, the browser sends the entered text as q, to /search using a GET request appending it as a query string (/search?q=some_text)
Comments
Post a Comment