What a Form Is and How Its Data Reaches the Server
Quick answer A form collects information in the browser and sends it as name=value pairs to a program on the server. HTML designs the form; a server-side script processes it.
A form is the part of a web page that collects information from the person using it and sends that information to a program running on a web server. Every time you search for a train on IRCTC, log in to a school portal, apply for an examination or pay a fee through UPI, you are filling in a form.
To follow where the data goes, recall the client-server model. The client is the browser on your computer or phone. The server is the computer that stores the website and answers requests for it. The two talk using HTTP (HyperText Transfer Protocol), the set of rules for transferring web pages, or its secure version HTTPS. The address you type, such as www.example.com/register.html, is a URL (Uniform Resource Locator) — the complete address of a resource on the web. A school website and IRCTC differ only in what they store; the mechanism is identical.
The journey of form data has four steps, and it is worth being able to state them in order:
- The browser displays the page containing the form. The boxes, buttons and lists inside it are called controls (also called form elements).
- The user types or selects values and clicks the submit button.
- The browser gathers every named control into a set of name=value pairs and sends them to the address written in the form's
actionattribute. - A server-side script at that address — a program written in a language such as PHP or Python — reads the values, stores them in a database or file, and sends back a reply page such as Registration successful.
The single most important idea in this chapter is the name=value pair. The name attribute that you write in the HTML supplies the name; whatever the user typed or ticked supplies the value. If a student types Anjali into a box written as <input type="text" name="sname">, the browser sends sname=Anjali. Two or more pairs are joined by an ampersand:
sname=Anjali&cls=10&city=Delhi
Now the limitation you must be able to state. HTML only designs the form and sends the data. It cannot process anything. HTML has no way to add marks, compare a password with a stored one, or save a record. That work belongs to the server-side script. A form whose action points to nothing therefore collects data that is simply thrown away when the page is left. A safe one-line answer is: HTML is used only to design the form; the data entered is processed by a program on the server.
There is a small amount of checking the browser itself can do before it contacts the server — refusing to submit an empty box marked required, for example. This is called client-side validation. It is fast and saves a needless trip to the server, but how much of it happens depends on the browser and its version, and a determined user can get around it. Real websites therefore check the same data again on the server. For your paper, remember the pair of terms: client-side validation happens in the browser, server-side validation happens on the server, and serious sites do both.
Finally, note the difference between a form and a form control. The form is the container, written with the <form> tag. The controls are the individual items inside it — text boxes, radio buttons, checkboxes, drop-down lists, the submit button. Questions that ask you to name any four form controls want the controls, not the container.
- A form is the part of a web page that collects data from the user and sends it to a program on the web server.
- The items inside a form — boxes, buttons, lists — are called controls or form elements.
- Data travels as name=value pairs, several pairs joined by an ampersand.
- HTML only designs the form and sends the data; a server-side script processes and stores it.
- Client-side validation happens in the browser, server-side validation on the server; reliable sites do both.
- HTTP is the protocol used to transfer web pages; a URL is the full address of a resource.
