Handling HTML forms
HTML forms are an essential component of capturing data in web applications. An HTML form can be processed on the server side through the use of a Form
HTML element, or it can be processed on the client side using JavaScript. In this section, we will look at handling HTTP form submissions for server-side processing.
How to do it...
On the client side, do the following.
- Enclose data input fields in a
Form
HTML element:<form method="POST" action="/auth/login"> <input type="text" name="userName"> <input type="password" name="password"> <button type="submit">Submit</button> </form>
Here, the
method
attribute determines the HTTP method, which isPOST
, and theaction
attribute determines the URL. Note that this URL is relative to the current page URL. When the form is submitted, the client-side processing will prepare aPOST
request for the given URL...