The Web Design Group

Web Authoring FAQ: HTML Forms


This list of Frequently Asked Questions is maintained by the WDG and was last updated on November 29, 1999. It may be found at the following URLs:

If you would like to contribute to this FAQ, please send mail to <darin@htmlhelp.com>. All contributors will be listed at the bottom of the FAQ.

7. HTML Forms

  1. How do I use forms?
  2. How do I get form data emailed to me?
  3. How do I make a form so it can be submitted by hitting ENTER?
  4. How can I make a form with custom buttons?
  5. Can I have two or more Submit buttons in the same form?
  6. How can I allow file uploads to my web site?
  7. How can I use forms for pull-down navigation menus?

7.1. How do I use forms?

The basic syntax for a form is: <FORM ACTION="[URL]">...</FORM>

When the form is submitted, the form data is sent to the URL specified in the ACTION attribute. This URL should refer to a server-side (e.g., CGI) program that will process the form data. The form itself should contain

A more detailed explanation of the use of forms is available at <URL:http://www.hut.fi/u/jkorpela/forms/>. If you want to install CGI programs on your server, the following are useful resources:

[Table of Contents]

7.2. How do I get form data emailed to me?

The only reliable mechanism for processing form submissions is with a server-side (e.g., CGI) program. To send form data to yourself via email, you should use a server-side program that processes the form submission and sends the data to your email address.

Some web service providers make standard form-to-email programs available to their customers. Check with your service provider for details.

If you can install CGI programs on your own server, see the answer to the previous question for a list of useful resources.

If you can't run CGI programs on your own server, you can use a remotely hosted form-to-email services. A list of such services can be found at <URL:http://www.cgi-resources.com/Programs_and_Scripts/Remotely_Hosted/Form_Processing/>. Note that the provider of a remotely hosted service will have access to any data submitted via the service.

Forms that use ACTION="mailto:..." are unreliable. They may work for some of your users, but they will fail for others who have different software configurations.

[Table of Contents]

7.3. How do I make a form so it can be submitted by hitting ENTER?

The short answer is that the form should just have one <INPUT TYPE=TEXT> and no TEXTAREA, though it can have other form elements like checkboxes and radio buttons. For a more detailed answer, see <URL:http://ppewww.ph.gla.ac.uk/%7Eflavell/www/formquestion.html>.

[Table of Contents]

7.4. How can I make a form with custom buttons?

Rather than a normal submit button (<INPUT TYPE=submit ...>), you can use an image of a custom submit button. Use <INPUT NAME=Send TYPE=image SRC="http://url.to/image.gif" ALT="Send" VALUE="Send">. Most browsers will also send the x and y coordinates of the location where the user clicked on the image to the server. They are available as "Send.x=000&Send.y=000" in the CGI input. For more information, see <URL: http://ppewww.ph.gla.ac.uk/%7eflavell/www/trysub.html>.

For the reset button, one could use <BUTTON TYPE=reset ...>, JavaScript, and/or style sheets, although none of these mechanisms work universally. For more information, see <URL:http://www.hut.fi/u/jkorpela/forms/imagereset.html>.

[Table of Contents]

7.5. Can I have two or more Submit buttons in the same form?

Sure. This is part of HTML 2.0 Forms support (some early browsers did not support it, but browser coverage is now excellent).

You will need to give your Submit buttons a Name attribute, and, optionally, a Value attribute. In order to determine which button was used, you will want to use distinctive Names, or Values, or both. Browsers will display the Value, in addition to sending it to the server, so choose something that's meaningful to the user.

Example:

<INPUT TYPE=SUBMIT NAME=join VALUE="I want to join now"> -or-
<INPUT TYPE=SUBMIT NAME=info VALUE="Please send full details">

If you're unsure what results you're going to get when you submit your form, NCSA has a standard script which you can use. Code this, for example (assuming method "post"):

<form method="post" action="http://hoohoo.ncsa.uiuc.edu/htbin-post/post-query">

and then go through the motions of submitting your form. The NCSA server decodes the form input, and displays the result to you.

[Table of Contents]

7.6. How can I allow file uploads to my web site?

First of all, the RFC for this is located at <URL:http://www.ics.uci.edu/pub/ietf/html/rfc1867.txt>.

File upload is handled by the CGI.pm Perl5 library available from <URL:http://stein.cshl.org/WWW/software/CGI/cgi_docs.html>. The most recent versions of the cgi-lib.pl library also support file upload.

These things are necessary for Web-based uploads:

Not all browsers support form-based file upload, so try to give alternatives where possible. Also, if you need to do file upload in conjunction with form-to-email, the Perl package MIME::Lite handles email attachments.

[Table of Contents]

7.7. How can I use forms for pull-down navigation menus?

There is no way to do this in HTML only; something else must process the form. JavaScript processing will work only for readers with JavaScript-enabled browsers. CGI and other server-side processing is reliable for human readers, but search engines have problems following any form-based navigation.

See <http://www.hut.fi/u/jkorpela/forms/navmenu.html>, which explains how to create pull-down menus, as well as some better navigation alternatives.

[Table of Contents]


For additions or omissions to this FAQ, please contact <darin@htmlhelp.com>.

All information contained herein was originally compiled by members of the Web Design Group, principally Arnoud "Galactus" Engelfriet, John Pozadzides, and Darin McGrew.

Additional input has been provided by Boris Ammerlaan, Lori Atwater, Alex Bell, Stan Brown, Roger Carbol, Alex Chapman, Jan Roland Eriksson, Jon Erlandson, Mark Evans, Alan Flavell, Lucie Gelinas, Bjoern Hoehrmann, Tina Marie Holmboe, Peter Jones, Nick Kew, Jukka Korpela, Simon Lee, Nick Lilavois, Neal McBurnett, Glen McDonald, Dan McGarry, Ken O'Brien, Timothy Prodin, Steve Pugh, Liam Quinn, Colin Reynolds, Kai Schätzl, Doug Sheppard, Sue Sims, Toby Speight, Warren Steel, Ian Storms, Peter Thomson, Daniel Tobias, and Diane Wilson.

Thanks everyone!


Home, Reference, FAQs, Tools, Design, Feature Article, BBS, Links

Copyright © 1996-1999. Web Design Group All rights reserved.