Forms and form elements are used by web developers to collect data & information from users on websites. This can include;
The most common example of a form in use is a searchbox, such as Google or Bing.
Please read the following for basic information about forms:
<form>
ElementTo include a form in a webpage we must declare a form element section. This is simply accomplished by using the <form>...</form>
tags.
Between these tags will be separate “form elements” such as “text boxes” and “buttons” that we will discuss in the proceeding pages.
The following are attributes that you should always include in a form element tag.
action
The action
attribute is a link to a server-side script (i.e. a file on another computer, not the users computer). Typically this file is code file (php, javascript, python, java, etc) on a server that will do ‘something’ with the user data before returning information back to the browser.
The value of the action attribute will always be an URL.
method
Forms can be sent using one of two methods; ‘get
’ or ‘post
’.
With the ‘get
’ method, values are added to the end of the specified action URL.
This methods is ideal for searches, or for retrieving data from a server (as opposed to sending data that will be stored in a database).
With the ‘post
’ method, values are sent in what are known as ‘HTTP headers’. As a rule of thumb, use the ‘post
’ method when;
id
& class
As with many other elements in HTML, you should assign a unique element id
and class
that can be used by other languages to refer to the specific form.
<form action="http://www.example.com/subscribe.php" method="get" id="basicForm">
<!-- This is where the related form elements and controls will appear. -->
</form>