Adding a form to a page

Forms are intended for data exchange between a user and a server. The scope of the forms is not limited to sending data to the server, with the help of scripts you can access any element of the form, modify it and apply it at your discretion.

To indicate to the browser where the form starts and ends, the <FORM> tag is used (example 1). Between the opening and closing <FORM> and </ FORM> tags, you can place any necessary HTML tags. This allows you to add form elements to table cells to format them, and also use images. A document can contain several forms, but they should not be nested one in the other.

Example 1. Adding a form to a document

<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> Forms </ title>
</ Head>
<Body>

<Form>
<P> Here are the elements of the form </ p>
</ Form>

</ Body>
</ Html>

Any form contains several parameters:

  1. Elements of the form, which are standard fields for entering information.
  2. The button for sending form data to the server.
  3. The program address on the web server that will process the contents of the form data.

To specify to the browser where and how to send form data two parameters are used:

Action is the address of the CGI program that receives the form data. This is a required parameter for the <FORM> tag.

Method - a method for transferring data contained in a form from the browser to the web server. It can take two values: get and post .

When using the GET method, the form data is sent as part of the URL request and is listed after the question symbol (?). For example, the query string can look like this:
Http://www.shram.kiev.ua/cgi-bin/program.cgi?name=Vasya&lastname=Pupkin

With the POST method, the data is passed to the web server in the request body, and their size can be quite large (example 2).

Example 2. Form with the parameters action and method

Valid HTML
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> POST method </ title>
</ Head>
<Body>

<Form action = "/ cgi-bin / program.cgi" method = "post">
<P> Here are the elements of the form </ p>
</ Form>

</ Body>
</ Html>

The GET method is used by browsers by default, so when you select the method for sending data to the server, the method = "get" parameter can be omitted.

When you place a form in a table cell, automatically around it, fields are added above and below. To remove them, add a style margin parameter with a value of zero to the <FORM> tag (example 3).

Example 3. Using styles to set indents in a form

Valid HTML
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> Indenting the form </ title>
</ Head>
<Body>
<Form action = "current.php" style = "margin: 0" >
<P> ... </ p>
</ Form>
</ Body>
</ Html>

Copyright © www.htmlbook.ru