Input field is a ten-headed hydra, creating a different form control depending on the value of its type attribute. With just this single element you can create text boxes, checkboxes, radio buttons, and more. There are 10 possible values for the type attribute,
- text - for single-line text
- password - for secret text
- checkbox - for a simple on or off
- radio button - for selecting one of a number of options
- submit - for sending the form data
- reset - for returning the form fields to original values
- hidden - for data not seen, or edited by, the user
- image - for sending coordinates of where an image is clicked on
- file - for uploading files
- button - for invoking client-side scripts
<input name="yearpublished" value="name" maxlength="99" size="20" />
<input name="email" size="20" maxlength="256" />
<input name="username" size="20" maxlength="256" />
An input element with the attribute type="text" is a single-line text box. This is the default value for the type attribute, when there is type value on the input element.
The label element is useful to denote what input elements are inside a form. The size attribute is used to define the size of the input text box and the maxlength attribute is used to limit the maximum number of texts inside the input text box.
<input type="password" name="passwd" maxlength="256" size="19" />
<input type="password" name="passcon" maxlength="256" size="19" />
The password value works same like an text value, where the only difference is that the texts are hidden(usally asterisks or circular bullets). This is to protect the users confidential data.
<input type="checkbox" name="top" checked="checked" />
<label>Subscribe to top news</label>
<input type="checkbox" name="tech" />
<label>Subscribe to technology news</label>
<input type="checkbox" name="weather" />
<label>Subscribe to weather news</label>
Checkbox value, produce checkboxes to supply yes/no or on/off option. By default, a browser will style this as a small empty square box, which when selected, will display a "tick" inside box.
To preselect the checkbox, you can use the checked attribute with checked value. Note that, in XHTML the value attribute must be present.
<input type="radio" name="vote" value="excellent" checked="checked" />
<label>Excellent, I love this blog</label>
<input type="radio" name="vote" value="good" />
<label>Yes, it's a good blog</label>
<input type="radio" name="vote" value="average" />
<label>Ahh...this blog is average</label>
The radio buttons are similar to checkboxes, except that you can select only one option in a group at a time.
You need to define the name attribute with a same value to the group of radio buttons. The checked attribute work same like in checkboxes and the value attribute is very necessary here, because without that, the radio buttons work like checkboxes.
<input type="submit" value="Submit" />
The most common and the easiest way of submitting a form is through submit button. When the submit button is pressed, the form will be redirected to the action attribute in the opening form tag.
The default text on the button will be "Submit Query", but this can be changed using the value attribute.
<input type="reset" value="Reset" />
The reset input type creates a reset button, which, when clicked will reset the form, with form fields returning to the values that they had when the page was first loaded.
Just like submit button, the text on the reset button can be changed with the value attribute. The name attribute is not necessary in both submit and reset buttons.
<input type="hidden" name="user" value="professor" />
<input type="hidden" name="date-submitted" value="22-05-1990" />
The hidden input type doesn't show up in the form and has nothing that the user can directly interact with.
The use of hidden attribute is that it can send hidden values along with the other datas in the form. Some example values are, sending date of form submission, sending order id, etc... But, you must remember, that you should not use this to hide confidential values, as any user who knows how to access the source code of a page, can easily take the data.
<input type="text" name="search" size="19" maxlength="1000" />
<input type="image" src="search_button.png" />
The image type is a cross between a submit type and img element. The source of the image should be noted with a src attribute and an alternate text for the image can be used with alt attribute.
<form action="preprocessor.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadfile" id="uploadfile" />
The file type allows user to select a file from their own computers, to upload a file.
To use file type value, an additional enctype attribute must be added to the opening form tag with the value "multipart/form-data", so that when it is sent the server knows that it is getting more than textual data. The method attribute must also be sent to post.