How is a html form submitted?

While other elements of HTML gives style and meaning to your website, an HTML form adds interactivity. HTML forms handle important functions like taking orders, surveys, user registration and more. You will hardly find a single web site without forms.

How does an HTML form work?

A web form has two parts: the HTML ‘front end’ and a back end form processor. The HTML front end part handles the presentation while the back end handles the form submissions (like saving the form submissions, sending emails etc). The back end form processor script is usually written in languages like PHP, ASP or Perl. The image below illustrates the concept:

How is a html form submitted?

  1. A visitor visits a web page that contains a form.
  2. The web browser displays the HTML form.
  3. The visitor fills in the form and submits
  4. The browser sends the submitted form data to the web server
  5. A form processor script running on the web server processes the form data
  6. A response page is sent back to the browser.

Do you want to make web forms quickly using a visual editor? Try Simfatic Forms.
More info:
How to Make Web Forms Quickly

Also see How to build a form video tutorial here:

The HTML form tag

All the input elements should be enclosed within the opening and closing <form> tags like this:

<form>

The input elements go here….

</form>

The following are the attributes of the form tag:

action="Link to the form processor script” The action attribute points to the server side script (the ‘back end’) that handles the form submission. Usually, this will be a script (PHP,ASP, Perl) or a CGI program.

For more information, see: Switching HTML form action field dynamically

method =get|post ( either GET or POST) In simple terms, if you use GET method, the form submission values are passed as part of the URL. If it is POST, the information is sent to the server as part of the data body and will not be visible in the URL box in the user's browser. If you don't specify the method, GET is taken by default.

Suppose your form handler page is a Perl script named formmail.pl. the HTML form code would be:

<form action="cgi-bin/formmail.pl" method="post">
................................
.....your input items here .....
................................
</form>

Read more about the HTML Form tag here and about the GET and Post methods here.

The form input elements

You can have different types of input elements in a form. Examples are: check boxes, radio buttons, simple text boxes etc.

Let us see how to create input elements for a form.

Single line text box

How is a html form submitted?

A single line text box can be used to collect the name, email, phone number etc from your web site visitors.

Here is the code to create a simple text box:

<input type="text" name="FirstName" />

type="text” the ‘type’ attribute tells the browser that a single line text input box should be created.

name="FirstName” gives a name to the field. The name is used to identify the field on the server side.

There are some more attributes that you can use with the text box

value="default value” The text you give as value will be displayed by default in the text box. Example:

<input TYPE="text" name="FirstName" value="Your FirstName here,Please" />

maxlength="maxChars” Specifies the maximum number of characters the user can enter into this text box.

Let us expand our previous HTML form with some text boxes.


<form action="cgi-bin/formmail.pl" method="post">
   <p>
   Name: <input type="text" name="FirstName" value="" size="25" maxlength="50" />
   </p>
   <p>
   Email: <input type="text" name="Email" value="" size="25" maxlength="50" />
   </p>
</form>


There are two fields in this form for collecting the name and email address of the visitor. The

tags are to break the input elements in to two lines.

Submit button

How is a html form submitted?

After entering the data, the user presses the submit button which triggers the browser to send the data to the server. You can add a submit button to the form using the ‘submit’ input type.

<input type="submit" name="submit" value="Submit" />

name ="submit” There can be more than one submit buttons in a form. On the server side, the submit button which was pressed can be identified using the ‘name’ attribute.

value="Submit” The string given in the ‘value’ attribute is displayed as the label of the Submit button.

Let us put it together to make a complete form page:

How is a html form submitted?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns='http://www.w3.org/1999/xhtml'>
   <head >
      <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
      <title >Form Page: sampleform</title>
   </head>
<body>
<h2>Sample form page</h2>

<form id='sampleform' method='post' action='' >
   <p>
   Name: <input type='text' name='Name' />
   </p>
   <p>
   Email: <input type='text' name='Email' />
   </p>
   <p>
   <input type='submit' name='Submit' value='Submit' />
   </p>
</form>

</body>
</html>

Copy this code to an HTML file and open it in your favorite browser.

See the form in action: HTML form tutorial example

Next part: HTML Form Tutorial Part II : More Input Elements

Also see: How to build a form: HTML Form Guide

See Also

  • HTML Form Tutorial Part II : More Input Elements
  • HTML Form Tutorial Part III : Still More Input Elements
  • HTML Form Tutorial Part IV: Server Side Form Processing
  • A Modern Reintroduction To AJAX
  • How to make a web form and get it online quickly
  • JavaScript Button
  • JavaScript Popup Windows
  • Using the window.close method
  • Using the window.open method
  • Can JavaScript email a form?

What happens when submit HTML form?

Most HTML forms have a submit button at the bottom of the form. Once all of the fields in the form have been filled in, the user clicks on the submit button to record the form data. The standard behaviour is to gather all of the data that were entered into the form and send it to another program to be processed.

Do HTML forms need a submit button?

If you don't have any submit button it is acceptable after all it is an element of form tag and if it is not required you may not add it with in form .

How does an HTML form work explain?

A webform, web form or HTML form on a web page allows a user to enter data that is sent to a server for processing. Forms can resemble paper or database forms because web users fill out the forms using checkboxes, radio buttons, or text fields.

How many different methods are there for submitting HTML forms?

In HTML, one can specify two different submission methods for a form. The method is specified inside a FORM element, using the METHOD attribute. The difference between METHOD="GET" (the default) and METHOD="POST" is primarily defined in terms of form data encoding.