| Viewed 545 times

how to create a form in html


how to create a form in html

1 Answer
Mikdam Qandeel
Answered
23

Form in HTML used to collect information and input from the user, such as contact details like name, phone numbers, email address.

We make the form in HTML using <form> tag.

Example:

<form>
        Here we are...
</form>

Any form in HTML contains elements called form elements.

These elements are different and have various purposes, we have a text field, submit button, password field, radio button, checkbox and A lot more.

The most important form element is<input>element, and the type of it depends on the type attribute.

Here is a small example of login form:

Example:

<form>
        <label>Username: <input type="text"></label>
    <br>
        <label>Password: <input type="password"></label>
    <br>
        <input type="submit" value="Submit">
</form>

Output:



 

On the other hand, We have form attributes.

Starting with:

  1. name: It defines the name of the form.
  2. action: It defines the URL of the program or script on the webserver that will be used for processing the information submitted via the form.
  3. method: It defines the HTTP method used for sending the data to the web server by the browser. The value can be either get (the default) or post.
    • get: Is used to request data from a specified resource and is's one of the most common HTTP methods.
    • post: Is used to send data to a server to create/update a resource.

Here is an Example contain some of the attributes.

Example:

<form name="form1" action="actionWebPage.php" method="get">
        First name: <input type="text" name="name1">
        <br>
        Last name: <input type="text" name="name2">
        <br>
        <input type="submit" value="Submit">
</form>

Output:

First name:
Last name:

 



Related Questions