Processing Online Forms
Processing Online Forms
Objectives
Define Online forms Know the use of online forms Discuss the content and input fields Appreciate the use of online forms by applying it to your project. Create an online form for comments and feedbacks
Online Forms
Online forms are Web pages purposely designed for gathering information of the internet.
The main use of online forms is to gather feedback or opinion from the users for data processing, usually through a database.
Content
To start building an online form, you should place inside the HTML body tags the <form> </form> tags. Then, you can organize it with the input empty tag. This is usually inside the <form> set of tags and its attribute type specifies the kind of input you are going to have. Another attribute, name, distinguishes one input field from another.
Input Fields
Types
Text fields Radio buttons Check boxes Text areas Select fields
Text fields
The primary information that you want to get from your Web page visitors would be their name and location.
Use text fields when you want the user to type letters or numbers in a form.
The web server will not know from which text field the input came from without the NAME attribute
To control the visible size of the text field, we use the size attribute. If the size attribute is missing, the default value is usually set the by the browser to 20 which stands for 20em.
<form> <input type=text name=firstname /> First Name <br /> <input type=text name=lastname /> Surname<br /> <input type=text name=location size=15 /> City or Town<br/> </form>
Another important attribute is maxlength. This sets the maximum number of characters that can be typed in the field. This attribute is helpful in cases where we have database length restrictions, or if we know the exact or maximum number of characters the user must provide.
Radio buttons
Radio buttons are used when you want the user to select only one option from a list. The type attribute here needs to be set to the value radio. Meanwhile, do not forget the name attribute because if you do, the user can only use one among the set of radio buttons in your page.
Radio buttons(continues)
The value attribute, which can be used to set a default value to the input text field, is also important. A radio button without a value becomes meaningless when submitted to the server because the server wont know what the button stands for.
Radio buttons(continues)
<p><b>What type of movie do you mostly prefer to watch?</b></p> <input type=radio name=movietype value=action /> Action
To group a set of related radio buttons together, their name attribute should be one and the same.
Radio buttons(continues)
Note that only one option can be chosen. The checked attribute can be used to set the default selection if we want to indicate a pre-chosen selection.
Check boxes
Check boxes are similar to radio buttons, but are used when you want to let the user select more than one option among a number of choices. The type attribute is set to the value checkbox.
Check boxes(continues)
<p><b>Where do you watch movies? Select all that apply</b></p> <input type=checkbox name=cinema value=action /> Cinema
Text Areas
Text areas are text fields that have more than one line for longer text input. Usually, they are used as a method to send comments or feedback. The tag changes to textarea
<textarea name=comments></textarea>
You can specify the dimensions of the textbox with the rows and cols attributes, which stand for the number of rows and columns.
There is even the option to include default text to appear in the field when the page loads.
Select fields
Select field provides drop-down menus that the user can access to be able to choose any information from a given list.
<p><b>What is your age group?</b></p> <select name=age></select> The select tag must have a name attribute to identify the checkboxes.
Select fields(continuation)
The <option></option> tags define the text that is displayed in the menu.
<p><b>What is your age group?</b></p> <select name=age> <option value=teenager>younger than 20</option> <option value=youngperson>between 21 and 35</option> <option value=noanswer>prefer not to say</option> </select>
Select fields(continuation)
You may add selected to show which option will be displayed when the page loads. If not provided, the first item is selected by default.