An HTML form is used to collect user input. The user input is most often sent to a server for processing The <form> element is a container for different types of input elements, such as text fields, checkboxes, radio buttons, submit buttons, etc.
<form>
form elements
<form/>
Action Attribute
The action attribute defines the action to be performed when the form is submitted, which usually leads to a script that collects the information submitted and works with it. if you leave it blank, it will send it to the same file.
<form action="action.php">
Method Attribute
The method attribute is used to define the HTTP method of the form which is either GET or POST.
<form action="action.php" method="get">
<form action="action.php" method="post">
GET Method
The GET method is mostly used to get data, for example, to receive a post by its ID or name, or to submit a search query. The GET method will append the form data to the URL specified in the action attribute.
www.buildwithme.com/action.php?firstname-share&lastname-love
POST Method
The POST method is used when submitting data to a script. The POST method does not append the form data to the action URL but sends using the request body. To submit the data from the form correctly, a name attribute name must be specified. As an example let’s send the value of the field and set its name to Lastname:
<input type="text" name="lastname" value="Mouse">
Target Attribute
The target attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form. The target attribute defines the name of, or keyword for, a browsing context (e.g. tab, window, or inline frame).
<form target="_blank">
Value | Description |
_blank | The response is displayed in a new window or tab. |
_self | The response is displayed in the same frame (this is the default). |
_parent | The response is displayed in the parent frame. |
_top | The response is displayed in the full body of the window. |