HTML Forms

  • Form is used to take data from user and pass it on server.
  • <form> tag is used to create a form.
  • The <form> tag is used for defining the user interface elements , like command buttons , text boxes etc...
  • To pass the data, two attributes of <form> are used-
    •   ◉ action= (Required) It defines the name of the file, to which the data will be transferred.
    •   ◉ method= (Optional) It defines the method of passing the data. It may have one of two values-
    •     ◆ get- This is the default value. In this method, the query is generated in the address bar and the data will be visible in url. This can be used for non- secure data.     ◆ post- In this method, the result is appended to the body of HTTP request and the data will not be visible. This is used for secured data.

Syntax:

<form action= "script url" method= "get|post">
<input>
<input>
<textarea>
.......
.......
</form>


Form Attributes

  • Here is the list of Form Attributes:

    Attribute Description
    accept-charset This attribute specifies that charset used in the submitted form.
    action This attribute specifies an address (url) where to submit the form.
    autocomplete This attribute specifies if the browser should autocomplete the form.
    enctype This attribute specifies the encoding of the submitted data.
    method This attribute specifies the HTTP method used when submitting the form.
    name This attribute specifies a name used to identify the form.
    novalidate This attribute specifies that the browser should not validate the form.
    target This attribute specifies the target of the address in the action attribute.


    HTML Form Controls