Lesson 8 - Forms


DW Cover


We have completed the first half of the our Introduction to Dreamweaver course. You've created a practice homework site incorporating the tools and techniques learned in the prior lessons. The remaining lessons will introduce you to forms, AP Elements (layers), and behaviors, and provide resources for dreamweaver extensions.

Creating Simple Forms using Dreamweaver

HTML forms can be used for search engines, questionnaires, hotel reservations, registration and order forms, surveys, data entry, shopping carts and e-commerce, user feedback, and a wide variety of other applications. The form is specified as part of an HTML document. The user fills in the form and then submits it. The user agent then sends the form's contents to a recipient, as designated by the FORM element. Typically, this is to an HTTP server, but you can also email form contents. The form is one of the first interactive elements in web design. When the user submits the form, the information is sent to a server where a script acts on the data - sorting and organizing the contents before forwarding the results. The html author can create a confirmation notice to the user after the user submits the form.

You will create the form using Dreamweaver but all forms require a form handler to process the form data. You can not do this part with Dreamweaver since this part requires scripting on the server. A Common Gateway Interface (CGI) script runs on the server and is one way to process the information from the form (known as form data). CGI scripts can be used for tracking counters, message boards, email discussion groups, jump menus, etc. Many CGI scripts were written in Perl but there are other languages and scripts for processing forms such as AppleScript, C or C++, UNIX, Visual Basic.

Some CGI scripts have required fields which may be case sensitive. Check with your ISP or sysadmin to see if the mailform they use has any required fields.

Internet Service Providers (ISP) and universities often provide CGI scripts that can be used for free but these institutions restrict direct access to a CGI script. Contact your ISP to get specifics from them on their CGI and form processing features. Often they will have a generic Thank You or confirmation page where they redirect the user after they submit the form. You can create your own redirect confirmation page as well.

You can do a search for scripts and find many free scripts on the internet that you can plug into your HTML source. One of my favorites is: Matt's Script Archive.

Instead of using CGI you can use PHP, Hypertext Preprocessor, which is a scripting language that is run mainly on Linux Web servers. It is often used to access a database for information which is then formatted to be displayed in html. It is free and offered through an open source license. Go to the PHP web site to learn more about it.

Forms are created by placing input fields within paragraphs, preformatted text, lists and tables. The element in which a user enters data is called the input field. Information entered by the user is called the value. Before you can use any of the form fields, you must create the form itself.

Behind the Scenes of Forms

This is not an HTML course but this Lesson will be more valuable if you create your form using the split view 'Show Code and Design View' button. This way you can see behind the scenes (the HTML source) as you create the elements in bottom pane of the Document Window.

1. On the Document Window toolbar select the Split Button to split your screen into Code and Design Views.

2. Open the Forms Category of the Insert Panel or go to the Insert Menu - Insert>Form>Form to create a form. Below, the Forms icons are shown in the Classic view which is selected from the Dreamweaver toolbar.

Forms Icons

Select the Form button to insert a form into your file. The Tag Editor comes up where you fill in the Form attributes. For now we will select the post Method.

Forms Tag Edit

Selecting this button will create the Form container tags represented by a red box in your Document Window. The contents of the form will go between the open form tag <form> and the end form tag </form>, i.e. within the red box.

Red Box around Forms

If you don't see the red box in your document window, go to the View Menu - Visual Aids>Invisible Elements and make sure that there is a checkmark to the left of Invisible Elements. You can use the tag selector in the bottom status bar of the Document Window to select the form.

When you select the form by clicking on the red dotted-lined rectangle, the property inspector displays the properties for the form. Here are the Properties for the Form tag in the PI.

form PI

Select the form and open the PI. For this lesson, leave the Target dropdown menu blank, the Class dropdown menu blank, set the Method to POST, and leave the Enctype dropdown field blank unless you're using an email address for the form action, in which case type the words "text/plain" without the quotes into the the Enctype field.

You can not drag the red dotted-lined rectangle to change the size of the form. The size of this form container is dependent upon the elements you put inside the form. Here are the properties available in the PI for the form.

The Form Icon is represented in the upper left corner by a square with a dashed line.

The Form Name is form1 by default but I recommend changing the name to something descriptive. Do not use spaces, special characters or reserved words. Let's use feedback for our Form name. Replace "form1" with "feedback"without the quotes. Note that DW will name the forms by default form1, form2, form3, etc.

The Action attribute is the destination of the form. Most likely, the destination will be the URL of the CGI or PHP mailform and will usually end with cgi-bin or cgi_bin or php. Get the address of the cgi/php from your ISP. You can also have the results of the form data emailed to you, in which case you'd put your email address in the action field preceded by mailto: so the complete address would read mailto:someone@somewhere.com. Using the mailto presents some problems so it's best to get the cgi-bin from your system administrator or ISP or use the information at the end of this lecture to connect to the formmail site.

The Method attribute is determined by the way or method the form will be processed, either CGI or Web-based application. Check with your ISP to see which method to use. GET is not a secure way to send the info so should not be used for sensitive info or e-commerce. Most of the time you'll use POST.

The Form fields based on the above information using a CGI script would be displayed in your HTML source code as:

<form action="http://www.somewhere.com/cgi-bin" method="post"  name="feedback">
    form goes here
</form>

 

or using PHP would be displayed in your HTML source code as:

<form action="http://www.somewhere.com/phpFileName.php" method="post"  name="feedback">
    form goes here 
</form>

 

or for those who are temporarily using an email as the form action, add text/plain for the enctype:

<form action="mailto:someone@somewhere.com" method="post" enctype="text/plain" name="feedback">
    form goes here 
</form>

 

Once you Insert the Form you can add Form Elements into the red box. You must insert all your form elements inside the red box. Many designers use Tables to create the layout for their form elements and then add labels or descriptive text associated with each label.

Note that it is better to use Div tags for layout rather than tables which you will do in the Positioning A value is required. lesson.

Insert a table of 100% inside your form and make 8 rows and 2 columns. You can adjust the rows and columns later by entering new numbers in the Property Inspector for the rows and columns. I recommend sketching a draft of your form on paper so you make sure you have all the proper form fields and labels to ensure that you'll collect the data you desire by making the form labels and input fields clearly laid out, defined, and intuitive for your user. Match the table inside your form to your sketch. HTML 4 has a new tag called Fieldsets which help in creating the structure of your form by grouping content or chunking related content into groups. You will read more about Fieldsets in this lesson.

Here is the FORMS Category of the Insert Bar. Notice that the icon buttons are divided into groups.
I have identified each button with its associated group below the image of the Insert Panel.

Forms Icons

Form Elements have at least three important attributes (some, as we will see, have more); these are the label that will appear on the form to describe the form element for the user, the name of the form element (which is important to the browser), and the value that will be reported to you when the user submits the form. When you click on the icon for most of the common form elements on the Insert>Forms tab of the Insert menu, you will see the pop-up box below, where you will specify the label you wish to associate with your form element. Enter the label you wish the user to see, leave the Style radio button on the default setting ("Attach label tag using 'for' attribute"), and choose the position for the label (before or after the form element) that suits your design. For now, ignore the Access key and Tab Index text boxes.

Form Label Definition

A few form elements require additional information, and will present a slightly more complex pop-up to you. You can set all other values for an element using the PI for that element; to view an element's PI, simply click on the element in your Design View window.

Form Elements

Text Field

Using the PI, you can define the size of the field by specifying the character width and maximum number of characters the field will hold. If you select password, the input display will only show asterisk characters. This does NOT function as a password protected site, it merely offers visual protection. Contact your server admin for info on securing and/or encrypting data for password protection.

The textfield will be empty to users until they input text *unless* you put an Init val (initial value) in the PI at authoring time. An initial value will be text that is displayed to the user when the page loads. Usually this text is instructional text or a prompt telling the user what you want them to do, and the user will select and type over the text. I recommend not using Init val for a textfield since users many not realize that you want to collect input data from them and they may skip over a field that is already populated with text.

If you disagree and can give examples of times when Init val may be helpful to the user, please post your comments on the Discussion Board.


The PI for Text Field

Form Field PI

Hidden Field
hidden fields
hidden fields
Read further in this lesson to learn more about Hidden Fields. Hidden Fields do not display in the Document Window or the browser. The image to the left appears in the Document window only. Check your code view and notice the code for your hidden field. The default will be:
<input type="hidden" name="hiddenField">

PI for Hidden Field

PI Hidden Field

Text Area
textarea

Compare the PI for this Textarea to the PI for the Text Field. The main difference is that the Type radio button is set to "Multi line" and the Wrap dropdown menu is available in the Textarea.  I set my Wrap to virtual. The Wrap menu options are: Default, which is the browser default; Off, which stop text from wrapping and creates one long line of text; Virtual which wraps in the browser but text doesn't wrap when it's submitted to the server; Physical which wraps in the browser and text does wrap when it's submitted to the server.

You can toggle the Type radio set of buttons to convert a Multi line Textarea into a Single line Text Field and/or Password and vice versa.

Type several lines into the Textarea on the left to see what happens when the box "overflows".


PI for Textarea

Form Textarea PI

Check Box
sailing
gardening
sewing
hiking
meditating

Checkboxes do not have to come in groups. If you use them in a group the checkbox name is the group's name. The checked value is the name of the check box. Use the PI to enter the group name -- in the example below, the group name is "hobbies". Use the Checked value text field to enter the value the form will report when that individual box is checked. Note that the checkbox label and value can be identical.

  • the checkbox name must be the same for all checkboxes within one group.
  • each check box value must be unique within the checkbox group
  • all checkboxes are unchecked by default
  • a user can select multiple check boxes

PI for Checkbox

PI checkbox

Radio Button
10 - 19
20 - 29
30 - 39
40 - 49
over 50

Radio buttons do not have to come in groups. To use them as a group you must supply the group's name along with a label and value for each radio button.   Use the PI to enter the group name as the Radio Button Name-- in the example below, the group name is "hobbies".   Use the Checked value text field to enter the value the form will report when that individual button is selected. Note that the radio button label and value can be identical.

  • the radio button name must be the same for all radio buttons within one group: e.g. "age"
  • each check box value must be unique within the checkbox group
  • only one radio button can be selected for each group of radio buttons - think of a car radio button, when you select one, the other station goes off.  YOU CAN ONLY HAVE ONE SELECTION WITH RADIO BUTTONS.  Test yours before submitting. GET THIS RIGHT!

The name of the button group goes in the textfield below on the left, below the Radio Button text. The default says "radiobutton".  This is the name that will be the same for all the radio buttons of a given SET or GROUP.  The Checked value is the descriptive name you assign to each button within a set, for example if your Radio Button set were named Gender, your Checked values for two buttons in the group could be Male and Female.


PI for Radio Button

PI Radio Button

Radio Button Group
radio group

Choose the vegetable!



The Radio Group button was added to make it easier to create sets of radio buttons. Selecting the Radio Group icon and then filling in the Labels and Values in the radio group pop-up box should make it easy for you to get your Radio buttons right! 


Pop-up for Radio Button Group

Radio Button Group

Dropdown List/Dropdown Menu

The Dropdown List and Dropdown Menu share a PI. Use the radio buttons on the PI to select the element you wish to use. A Dropdown list will allow multiple selections from its list - the user can shift+click or control+click to select more than one option. The list will scroll if you have more items than the number you enter for the height of the list.

Click on the "List Values..." button to enter or edit elements in your list/menu.

A Dropdown Menu allows only one selection from its values.


PI for List/Menu

PI list/menu

Jump Menu
jump menu
 
Details of the Jump Menu are listed later in this lesson. You will submit a Jump Menu for this week's homework. Please make sure that the Jump Menu is on a different .html page than the form that you will submit for this week's homework.

Image Field
 
Selecting the Image Field Button will open the Select Image Source dialog box where you can browse for an image to insert as a submit button.
You can use the image field to reset the form or attach a sound to a button using behaviors on the Form object which is covered in more advanced classes studying the use of behaviors in Dreamweaver.

File Field
August 15, 2010
I recommend that you NOT use this one your form. Anyone can upload a file with a virus attached and/or you may get spammed with files you don't want and didn't request. Use with caution.

Button


The button icon allows you to create the Submit and Reset buttons for your form. Use the PI to choose which button to create, and to change the button value -- the text which appears on the button.

I recommend always putting the Submit button before the Reset or Clear button. The reason is that users tend to use the Tab key on their keyboard to move to the next input area or form element. This is called setting the focus in a form field. The default order will set the focus on whichever button is closest to the top of the form. If a user is tabbing through and comes to the reset button, they might accidentally click and erase all their input.

You can set the tab order by using the Tab Index field of the Input Tag Accessibility Attributes Window. To open this window, go to your Preferences and select the Accessibilities category. Check the Form Objects box.

The None button can be used with scripts to perform calculations such as a script to return the sum of numbers.


PI for Button

PI Button

Label and Fieldset
label button
 
The label button lets you associate a text label for a field with the fieldset.
Read about a fieldset below.
fieldset
 

The fieldset button creates 2 container tags; a fieldset and legend as follows:
<fieldset><legend>fruits</legend></fieldset>

"The FIELDSET element defines a form control group. By grouping related form controls, authors can divide a form into smaller, more manageable parts, improving the usability disaster that can strike when confronting users with too many form controls. The grouping provided by FIELDSET also helps the accessibility of forms to those using aural browsers by allowing these users to more easily orient themselves when filling in a large form."

DW will automatically divide your Document Window into Split view when you select the fieldset button.

The fieldset is a new HTML4.0 element and you can read more about it here - the source of the above quote:
http://www.htmlhelp.com/reference/html40/forms/fieldset.html

Spry Validation Text Field
Spry Validation Text Field

Spry text fields have 14 different validation types as well as several other settings, such as an option to limit the minimum and maximum number of characters. None is the default setting which means no validation. You may set a pattern to validate against such as where numbers and letters are to be input. The following are the characters that are used to set the pattern:

  • 0 : A whole number from 0-9
  • A : Uppercase alphabetic letter
  • a : Lowercase alphbetic letter
  • B : Case insensitive alphabetic letter
  • X : Alphanumeric (uppercase letters and numbers)
  • x : Alphanumeric (lowercase letters and numbers)
  • Y : Case insensitive letters and numbers
  • ? : Any character (wild card)

Note that the characters in the pattern correspond to one character at a time. To set a pattern for B2B you would input XXX.

To show the Spry Validation Text Field in the Property Inspector you must click on the blue area where the Spry TextField label is. In this example it would be Spry TextField: sprytextfield1 in Design view.


PI for Spry Validation Text Field

Spry Text field PI

Spry Validation Textarea
Spry Validation Textarea
A value is required.

Spry textareas have far fewer validation options than text fields. You may specify whether the contents are required or not however you may not specify a patter. You have the option of showing the number of characters typed in and you may specify the maximum number of characters allowed. By setting a maximum value you may also choose to show the number of characters remaining.


PI for Spry Validation Textarea

Spry Validation Textarea PI

Spry Validation Checkbox
Spry Validation Checkbox
Please make a selection.

Spry Validation Checkbox ensures that a particular checkbox has been selected. A single checkbox is useful for situations that require the user to agree to your rules and conditions.

Adding a group of checkboxes is more complex and may be done in Code view or in Design view by following a rigorous set of steps. Look in "Dreamweaver CS3 The Missing Manual" by David Sawyer McFarland to see the steps required in order to accomplish this.


PI for Spry Validation Checkbox

Spry Validation Checkbox PI

Spry Validation Select
Spry Validation Select
Please select an item.

Spry Validation Select validates the selection of pull-down menus and has two options to determine whether the selection is valid or not. They allow you to not allow a blank value or an invalid value.

A pull-down menu is created with a label and a value. The label is what the user sees and the value is what gets sent to the server. If the value is invalid the form will not be submitted and an error message will be displayed.


PI for Spry Validation Select

Spry Validation Select PI

Spry Validation Password
Spry Validation Password Icon
A value is required. Please select an item.

Spry Validation Password works in conjuction with a password text field that can be used to enforce password rules (number and type of characters) and provide warning or error messages to the user. The widget provides warning or error messages based upon a user's input.

You can alter the properties of these states by editing the corresponding CSS file (SpryValidationPassword.css), depending on the desired validation results. A Validation Password widget can validate at various points—for example, when the site visitor clicks outside the text field, when they type, or when they try to submit the form.


PI for Spry Validation Password

Spry Validation Password PI

Spry Validation Confirm
Spry Validation Confirm Icon
A value is required.The values don't match. Please select an item.

Spry Validation Confirmis a text field or a password form field that displays valid or invalid states when a user enters a value that does not match the value of a similar field in the same form. For example, you can add a Validation Confirm widget to a form that requires a user to re-type the password they've specified in a previous field. If the user fails to type the password exactly as they've specified it previously, the widget returns an error message stating that the values do not match.

The Validation Confirm widget includes a number of states (for example, valid, invalid, required, and so on). You can alter the properties of these states by editing the corresponding CSS file (SpryValidationConfirm.css), depending on the desired validation results. A Validation Confirm widget can validate at various points—for example, when the site visitor clicks outside the widget, when they type, or when they try to submit the form.


PI for Spry Validation Confirm

Spry Validation Confirm PI

Spry Validation Radio Group
Spry Validation Radio Group Icon




Please make a selection.
Please select an item.

Spry Validation Radio Group determines if the field is required and can check for empty and/or invalid values. To create a Validation Radio widget, you only need a simple radio button input group that can be turned into a Spry Validation Radio widget by adding a few elements to it.


PI for Spry Validation Radio Group

Spry Validation Radio Group PI

The form above is a non-functioning form so if you click the submit or reset button, no action will be taken.

List Values Dialog for List/Menu Buttons

List menu

Use the tab key to add new Item Labels and Values. The Labels appear to the viewer in the list and the Values are submitted and parsed by the form handler. Notice that the Value can be the same word as the label. If the Value is the same word or a different word than the Item Label, it should be descriptive.

Add items with the + and delete items with the -. Use the triangular arrows on the right to reorder the list items.


Hidden Fields

Hidden fields are invisible in the html page but viewable in the source of the HTML document. You can put your hidden fields anywhere in your form but the standard location is at the beginning of the form. It's helpful to add a comment describing the purpose of the field. You can add comments to your document by going to the Common Panel of the Insert Panel and using the Comment Button.

Comment

Comment Box

This yellow exclamation point icon is the comment icon in the DW document window. Select this icon to open the Property Inspector for the selected comment. You must enable View>Visual Aids> Invisible Elements and check the box next to comments in Preferences...>Invisible Elements.


Jump Menus

A Jump Menu is a form element which displays as a dropdown menu of linked URLs used for navigation. Since it is a form element, jump menus must be contained within the form beginning and ending tags. Dreamweaver's Insert Jump Menu feature adds JavaScript behaviors to the form menu element. Although the jump menu is a form element, all the processing is done on the client side through JavaScript and the jump menu does not require a form handler or a submit button. Please create a new form in which to contain your jump menu rather than grouping it with another form that requires a handler or cgi script on the server side.

Create a basic jump menu. Do not include a jump menu within any other form tag. It should always be in it's own separate form. GET THIS RIGHT PLEASE. You won't believe how many students put their jump menu within their form homework. Create a jump menu on a separate html page than your submissible form.

You can link your jump menu selections to any external absolute URL or any relative files in your site, including graphic and .pdf files. You can use behaviors to replace the standard Go button with an image when you learn more advanced features of DW.

To make the first item of your jump menu informational without jumping anywhere upon selection, add the information to the item label and then deaden the link by setting the value to javascript:void('');. Note that the quotes within the parantheses are two single quotes.

Here is a jump menu that does not use a GO button and the first item is informational and does not jump anywhere:

To get your jump menu to open each URL in the current window or a frame, see these Adobe Tech Notes and Tutorials: Jump Menus

The Go Button - make sure that the Go button is ONLY there if you are not programming the menu to jump automatically when an option is selected. This is really important so read carefully.
TechNote: Jump Menu and Go Button Options

Targeting Frames from the Jump Menu:
TechNote: Setting a Target Frame in a Jump Menu

Go to Project 7's Web site check out their amazing extensions.

Adobe's Tech notes

Please visit Adobe's Tech notes Index for specific problems OR when you get stuck and no one has replied to your forum post!

TechNote Index

Form Validation

Dreamweaver has a behavior which will validate your form. In other words if you want a proper email address in an email field, this behavior will check the formatting of the entry and notify the user with an alert box if they have not used a standards blank@blank.com email address. You can use this behavior to make some or all fields required. If the user submits without filling in the required fields, an alert box will display a message that you create informing them they need to fill out the required fields, etc.

Please keep the form assignment so that you can apply the form validation behavior when we learn to use behaviors later in the course. (soon!) You will be required to use form validation on the form page of your final project.

Form Tips

Always contact your ISP or sys admin for specific instructions on uploading forms to your server.

Use a unique name for each hidden field you use.

If you're allowing multiple selections for a form field, inform the user with a short text explanation and info on how they can select more than one item for a group. Modifier keys may be different for different operating systems.

Radio buttons always come in groups or sets. Each option within a set has a value and each option must be part of the same named group or set. Radio buttons are used when only one option at a time can be selected, just like the radio buttons on an old car radio. When you select another button, it turns off the station that was previously selected ...hence the name: radio button!

Checkboxes may come in groups or sets or by itself. Each option within a set has a value and each option in a set must be part of the same named group or set. Use checkboxes for multiple selections.

You can use the Submit button action set to None after you learn to use behaviors on form objects. Dreamweaver behaviors are written in JavaScript. You don't need to know JavaScript to use the behaviors with the form button.

For textarea Wrap property, use either Virtual or Physical to let the text automatically wrap within the text box. The difference between these options is how the text is sent to the CGI script. Wrap Physical preserves line wrapping that takes place in the text box and Virtual does not. Off displays all the text on a single line with horizontal scrolling until the Enter key is pressed. It's sent to the CGI as one single line of text.

You can set initial state of radio buttons and checkboxes within the Property Inspector. Select the form element and view the PI. I've selected unchecked for my samples above.

You can set an Initially Selected Option for List and Menu items. This can be a description or instruction rather than an option.

Name every element you use in your form.

You cannot nest forms which means you cannot insert another form within a form. You can, however, have more than one form on a page but I don't recommend it and I will not accept more than one form on a page for your final project. Just be certain to end one form before beginning another form.

Use tables to get a nice layout structure for your forms.

Jump Menus: You cannot add the GO button after you've closed the Insert Jump Menu dialog so it is best to add it and then delete it if you decide you don't want it later. For your final project make sure that you design the function of the jump menu to either immediately go to the selected URL - in which case you DON"T need the GO button so remove it OR you want to select a URL and then require the user to click the GO button to jump to the selected URL.

Using Formmail: Formmail provides tools and services to collect and process information from visitors to your web site. It allows you to hide your email address from your web forms. By using contact forms instead of a 'mailto:' link, spam bots will no longer be able to harvest your address. Formmail collects the information from your form and then emails it back to you.

Contact your web host to find out the URL they want you to enter for the Form Action. This will enable people to fill out the form online and have the results submitted to you via email (in the most basic use of this feature).

For those using Foothill's UNIX server or who don't have a cgi bin with their web hosting service, sign up for a free trial account at Formmail.com - which is Matt's Script - and this service will process your form. I think you can register for $1/month after your trial. Worth it.

http://www.formmail.com/register/

Using Zoho for your database: If you need to store information from a form in a database on the server but don't know how to code it, Zoho offers a free version where you can create a form and a database without having to know the coding details. Visit the site to get an idea of what you can do: http://creator.zoho.com

Here is a video that describes how to use Zoho Creator:



Examples of how to use Hidden Fields

Do an Internet or reference book search for Hidden Fields. A classmate informed me that the link that was here and worked last month, is no longer active, so I removed it. This reflects the ever-changing nature of the web as a living and dying organism. Sites come and sites go. Please inform me if/when you find broken links. They are all active as of the date I uploaded this page.

"By way of example, let's imagine that you have a small newsletter signup box in several pages of your website. When a user signs up for the newsletter, you might want to know from which pages they are signing up and which ones they aren't. After a while, you might notice some trends about which page(s) users prefer to sign up from and which pages they don't. Then you could ask a question like 'Why do my visitors prefer to sign up from that page more often than this page?' This information might help you better design your site."

Read a few sites to learn more about both client- and server-side applications of hidden fields. Hidden fields are variables which are passed to the Forms Processor, like any other piece of data entered into a form by a client, except that hidden fields and their values do not show up in the browser. Hidden fields can be used to store information for server-side processing that are related to the information entered at the client side.

For example, a CustomerID can be assigned when customer fills out an inquiry form. The CustomerID can then be sent to the server and stored in the database along with other customer information. Another example is when a website has multiple forms, a hidden field at the beginning of each form can be used to verify identification when any of the forms is submitted. I just wanted to point out that if there are multiple forms to fill out, hidden fields can contain this info and populate the rest of the forms after you have filled out the first one. Saves time when you track a user across multiple dynamically generated forms so that you can pre-fill user data for things that user already entered. A password will not be displayed on the screen as the person types it in. The price of items being purchased might be in a field that is hidden for some documents, such as a shipping form. When a person fills out a form to purchase an item by credit card , the credit card number, or perhaps all but the last four digits, might be in a hidden field. As the creator of the form, you might want to know the URL of the form, or the version number of the form, sent back to you as a hidden field.

Hidden fields should be used when sensitive information is being communicated. Examples include password information and credit card information. The use of hidden fields range from sensitive data to developer's comments in case you're part of a team working on the same site. However, a hidden field is not a comparable substitute for cookies. A hidden field is not secure since all the data is stored in the source. Leaving the page and coming back to it does not retain the data like persistent cookies can.

Hidden fields can be useful for collecting user data. For example, let's say you are a webmaster in a marcom organization and you are asked to create a form to collect user data for a promotion your company is running. The objective is to pre-qualify potential customers so that members of the sales force can follow up with them. But what if you've already used that form for an earlier campaign? The sales force doesn't want to work a dead-end lead and risk alienating a potential sale. If you add a hidden field to your form that denotes campaign-specific data, you can now analyze the data from repeat customers and search for trends and craft strategies that best target that particular customer. - Jeff Cooper

Client-side and server-side field data will be treated by the server in the same manner as the data input by the client. The only difference is that the information is not visible to the client. Some features that are enabled as a result:

  1. Noting the time/date when a page was accessed
  2. Noting the url of the page that was accessed
  3. Redirecting the user to a different page after a certain action by the user (appropriate link, thank you message, end-of-submission page
  4. Alerting the user with some response (warning, hint)
  5. Identifying a user and his/her course of action on a page (counter, page-tracking)
  6. Sending a piece of information/alert/subject header that will ignite a response from the server

One of the main uses of hidden fields that I know of, is to store state information in the web page when a web application moves you through a series of steps, like:

  1. page 1: select products
  2. page 2: enter credit card info
  3. page 3: select shipping method, etc,

The web server isn't supposed to keep track of where you are in the process. But the server needs to know the answers that you filled in on page 1 after you complete page 3. So the web page for page 3 can be written to include your answers from page 1 as hidden fields on page 3 when page 3 is generated. This makes it easy for you to be on page 3, then hit back twice to get to page 1 and just start from there again without confusing the web server.

An example of a hidden field is when some data should not be viewed by the visitor but is required for form processing. For example:

<input type="hidden" fname="Jane" value="Jane">
<input type="hidden" lname="Doe" value="Doe">

The hidden field another student used on her form:

<input type="hidden" name="recipient" value="hername@yahoo.com">  

This line of code was required by her host server in order to get the mailto command to work. You can also add other hidden fields which will direct the user back to your home page after submitting the form. Ask your web host what they require to make your form function.

You can use hidden fields to embed text in a form that will be submitted along with the other data. This can be used by the server receiving the data to sort out which version of the form is sending the data and how

Do not put sensitive information in a hidden field.  Remember, hidden fields are displayed if a user views the HTML source.

This will put a subject in the subject line of your email:

<input type="hidden" name="subject" value="Your Subject">

This will send the user to a thank you or confirmation page:

<input type="hidden" name="redirect" value="http://www.domain.com">  


Read: http://www.echoecho.com/htmlforms07.htm for more info on form fields.


More about Forms

Tutorial: http://www.smartwebby.com/web_site_design/dreamweaver_form_tips.asp

Make your form element show customized fonts and/or background colors.

Form Textarea PI

You can select a defined class from the Class dropdown menu and apply it to any form element or the entire form. For instance I have defined a class called v12greenBG. For this class, I defined the font to Arial white 12 points, and the background to green-blue. When I assign this class to a textfield, the background of the textfield will be green-blue to the user and as the user types data, it will appear in white Arial 12 point font.

Form Text Area Class

Here is how this textarea appears when I set the Char width to 40, the Num Lines to 6, and the Wrap to Virtual:

Class displayed in the browser


customized form elements

Make sure to include a form action. I left mine null in the example above using the pair of quotes: ""


Tips on Forms Layout:

A user should be able to tab from table cell to table cell of your form. Evaluate the layout of your form by resizing your browser window to see if you want/need to make any adjustments. Often when you make the browser window smaller you get strange layout of the names fields, checkboxes and radio button sets. If you put those in tables (even nested tables), you have more control over them when the user resizes the browser. For instance you can put the form label in one call and the form element in another to control the layout as such:

form label form element
name
checkboxes:
favorite music
rock
classical
jazz
like rap?
yes no

See how I've added tables within the form element column to have more control over the placement of the elements and the form labels to their left? This way if I resize the browser, I know that the rock label will always stay on the same row line as the checkbox for the rock option, etc.

If you don't do this, you may be surprised at how your viewers see your form. You may get last names in first name fields and improperly checked option boxes and buttons.

Always view your site with several sizes of browser windows to see how the changes affect your layout and see if you can implement more control over the layout. Please note that in the form above there is no submit or cancel button. Also note that the user cannot both like rap and not like rap. Radio buttons are used when you only want ONE reply - either yes or no, on or off, blue OR red but NOT both, etc.

You are not required to use a form validation behavior for this homework. Behaviors are taught in another lesson. However - please use the forms validation behavior on your final website. In addition, when you collect data, you want to make sure that you name your form elements descriptively so that you know what you mean when you get back a YES or NO reply, or some text returned to you by the server.

For example, this is what I received when I clicked on a previous student's submit button without filling out required fields. This is meaningless to both the user and to the author - and/or those processing the data. Name all of your labels and elements descriptively. For instance in the form reflected by the alert box below, textfield was firstname, textfield2 was lastname, textfield3 was email, etc.

script alert for form data errors


Resources and Examples

Up Arrow Top