Microsoft.NET

……………………………………………….Expertise in .NET Technologies

HTML Forms – Part 3

Posted by Ravi Varma Thumati on December 15, 2009

HTML Forms

Forms are a vital tool for the webmaster to receive information from the web surfer, such as: their name, email address, credit card, etc. A form will take input from the viewer and depending on your needs, you may store that data into a file, place an order, gather user statistics, register the person to your web forum, or maybe subscribe them to your weekly newsletter.

Text Fields

Before we teach you how to make a complete form, let’s start out with the basics of forms. Input fields are going to be the meat of your form’s sandwich. The <input> has a few attributes that you should be aware of.

type – Determines what kind of input field it will be. Possible choices are text, submit, and password.

name – Assigns a name to the given field so that you may reference it later.

size – Sets the horizontal width of the field. The unit of measurement is in blank spaces.

maxlength – Dictates the maximum number of characters that can be entered.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

Name: <input size=”10″ maxlength=”40″> <br />

Password: <input size=”10″ maxlength=”10″>

</form>

Input Forms:

Name:
Password:

Do not use the password feature for security purposes. The data in the password field is not encrypted and is not secure in any way.

HTML Form Email

Now we will add the submit functionality to your form. Generally, the button should be the last item of your form and have its name attribute set to “Send” or “Submit”. Name defines what the label of the button will be. Here is a list of important attributes of the submit:

In addition to adding the submit button, we must also add a destination for this information and specify how we want it to travel to that place. Adding the following attributes to your <form> will do just this.

method – We will only be using the post functionality of method, which sends the data without displaying any of the information to the visitor.

action – Specifies the URL to send the data to. We will be sending our information to a fake email address.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

Name: <input size=”10″ maxlength=”40″> <br />

Password: <input size=”10″

maxlength=”10″><br />

<input value=”Send”>

</form>

Email Forms:

Name:
Password:

Simply change the email address to your own and you will have set up your first functional form!

HTML Radio Buttons

Radio buttons are a popular form of interaction. You may have seen them on quizzes, questionnaires, and other web sites that give the user a multiple choice question. Below are a couple attributes you should know that relate to the radio button.

value – specifies what will be sent if the user chooses this radio button. Only one value will be sent for a given group of radio buttons (see name for more information).

name – defines which set of radio buttons that it is a part of. Below we have 2 groups: shade and size.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

What kind of shirt are you wearing? <br />

Shade:

<input value=”dark”>Dark

<input value=”light”>Light <br />

Size:

<input value=”small”>Small

<input value=”medium”>Medium

<input value=”large”>Large <br />

<input value=”Email Myself”>

</form>

Radios:

What kind of shirt are you wearing?
Shade: Dark Light
Size: Small Medium Large

If you change the email address to your own and “Email Myself” then you should get an email with “shade=(choice) size=(choice)”.

HTML Check Boxes

Check boxes allow for multiple items to be selected for a certain group of choices. The check box’s name and value attributes behave the same as a radio button.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

Select your favorite cartoon characters.

<input value=”Goofy”>Goofy

<input value=”Donald”>Donald

<input value=”Bugs”>Bugs Bunny

<input value=”Scoob”>Scooby Doo

<input value=”Email Myself”>

</form>

Check Boxes:

Select the 2 greatest toons.

Goofy

Donald

Bugs Bunny

Scooby Doo

HTML Drop Down Lists

Drop down menues are created with the <select> and <option> tags. <select> is the list itself and each <option> is an available choice for the user.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

College Degree?

<select>

<option>Choose One</option>

<option>Some High School</option>

<option>High School Degree</option>

<option>Some College</option>

<option>Bachelor’s Degree</option>

<option>Doctorate</option>

<input value=”Email Yourself”>

</select>

</form>

Drop Down Lists:

Education? Choose One Some High School High School Degree Some College Bachelor’s Degree Doctorate

HTML Selection Forms

Yet another type of form, a highlighted selection list. This form will post what the user highlights. Basically just another type of way to get input from the user.

The size attribute selects how many options will be shown at once before needing to scroll, and the selected option tells the browser which choice to select by default.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

Musical Taste

<select multiple size=”4″>

<option value=”emo” selected>Emo</option>

<option value=”metal/rock” >Metal/Rock</option>

<option value=”hiphop” >Hip Hop</option>

<option value=”ska” >Ska</option>

<option value=”jazz” >Jazz</option>

<option value=”country” >Country</option>

<option value=”classical” >Classical</option>

<option value=”alternative” >Alternative</option>

<option value=”oldies” >Oldies</option>

<option value=”techno” >Techno</option>

</select>

<input value=”Email Yourself”>

</form>

Selection Forms:

Musical Taste

Emo Metal/Rock Hip Hop Ska Jazz Country Classical Alternative Oldies Techno

HTML Upload Forms

First of all, to actually make the upload form function correctly you must know a scripting language of some sort. PHP and PERL work fine, Javascript is also an option. We have an entire upload example demonstrated here, PHP File Upload. The HTML code for the upload form does nothing more than create an interface for the user to see and work with.

An upload form consists of three basic parts. The first being a hidden field. This hidden field does nothing more than limit the allowed file size of our uploaded file. The second part is the input field itself. In this field, the user has the option to type in the full local URL of the file or he/she may click the browse button to thumb through directory after directory. HTML codes this automatically when we place the type=”file” attribute within the input tag.

HTML Code:

<input value=”100″ />

<input />

Upload Form:

HTML Text Areas

Text areas serve as an input field for viewers to place their own comments onto. Forums and the like use text areas to post what you type onto their site using scripts. For this form, the text area is used as a way to write comments to somebody.

Rows and columns need to be specified as attributes to the <textarea> tag. Rows are roughly 12pixels high, the same as in word programs and the value of the columns reflects how many characters wide the text area will be. i.e. The example below shows a text area 5 rows tall and 20 characters wide. Another attribute to be aware of is the wrap. Wrap has 3 values.

wrap=

“off”

“virtual”

“physical”

Virtual means that the viewer will see the words wrapping as they type their comments, but when the page is submitted to you, the web host, the document sent will not have wrapping words.
Physical means that the text will appear both to you, the web host, and the viewer including any page breaks and additional spaces that may be inputed. The words come as they are.
Off of course, turns off word wrapping within the text area. One ongoing line.

HTML Code:

<form method=”post” action=”mailto:youremail@email.com”>

<textarea rows=”5″ cols=”20″ wrap=”physical”>

Enter Comments Here

</textarea>

<input value=”Email Yourself”>

</form>

Text Area:

Also note that any text placed between the opening and closing textarea tags will show up inside the text area when the browser views it.

Advertisements

3 Responses to “HTML Forms – Part 3”

  1. Excuse me for writing off topic … which WP template are you using? It looks amazing.

    • Ravi Varma Thumati said

      Hi,

      Thanks for supporting my blog, i am using Andreas09 theme with customized blue color.

      Thanks
      Ravi Varma Thumati

  2. Congratulations on possessing certainly one in all one of the crucial refined blogs Ive arrive throughout in a while! Its just superb how a lot you’ll be capable to think about away from a factor basically merely due to how visually stunning it is. Youve place collectively a great weblog website space –great graphics, motion pictures, layout. This is certainly a should-see web site!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: