1. Technology

How to Make HTML Forms Work

Scripts and Tools to Send Form Data By Email and Other Form Actions


HTML forms are a great way to add interactivity to your website. You can find out a little something about your readers, give them a place for feedback, or even solicit submissions to your site. But they are often very frustrating for new Web designers, because HTML forms seem to have something missing within the HTML - they don't "work". In other words, while you can use HTML to create a form on a Web page, if you don't add some type of script or other action, your form won't do anything, even if your readers click on the submit button.

There are many different ways you can get your HTML forms to work. This article will discuss some of the most popular tools and give you the pros and cons to each of them. Then you can decide for yourself which method you'd like to use to make your HTML forms work.

Making HTML Forms Work with JavaScript

JavaScript is a popular method for making HTML forms work because it's easy to implement and can make your pages dynamic very quickly. But there are some definite drawbacks to using JavaScript for your HTML forms.

JavaScript for Forms Pros:

  • JavaScript is easy to implement
  • Most browsers support it

JavaScript for Forms Cons:

  • JavaScript cannot do anything on the server - it is limited to affecting changes to the browser only
  • You can't save form data with JavaScript

Good Uses for JavaScript in HTML Forms:

Making HTML Forms Work with PHP

PHP is becoming more and more popular with Web designers as it allows you to create dynamic pages that can interact with form elements and page elements while also using server scripting for more power and functionality.

PHP for Forms Pros:

  • PHP is very popular - there are many scripts available and developers to help you implement them
  • PHP integrates easily with mySQL and other databases
  • You can also use PHP to write data to files on the server

PHP for Forms Cons:

  • Not all servers support PHP (although not having PHP is getting less common)
  • You need to learn to program in order to use it
  • PHP is almost like learning another language on top of HTML that you use instead of (or alongside) your HTML
  • PHP has a lot of security issues that you need to stay on top of

Good Uses for PHP with HTML Forms:

Other languages that are similar to PHP in function include ASP and .Net and ColdFusion.

Making HTML Forms Work with CGI

CGI scripts are the oldest way that people have been making HTML forms work. The most common language used to write CGI scripts is Perl, but you can use C / C++ / C#, Delphi, Java, Python, Ruby, Visual Basic, or any programming language that the server can access.

CGI for Forms Pros:

  • CGI scripts, especially Perl scripts are very common on the Web. There are lots of CGI scripts for sale and programmers who can write them for you.
  • Nearly all hosting servers offer CGI access

CGI for Forms Cons:

  • CGI scripts can be slow to process
  • It's easy to write insecure scripts if you aren't careful
  • CGI requires that you learn a programming language
  • Hosting CGIs is more complicated than hosting plain Web pages or PHP

Good Uses for CGIs with HTML Forms:

Making HTML Forms Work with Mailto

Mailto forms are often the first choice of a beginning Web designer because they don't require any special programming skills. In fact, they are the closest thing to a form activation tool built-in to HTML. But mailto forms have a lot of problems. I don't recommend using mailto forms unless you have absolutely no other way to get a form working and you have to have it live immediately.

Mailto Form Pros:

  • Mailto forms are easy to set up
  • They don't require any special programming skills

Mailto Form Cons:

  • Mailto forms are unreliable
  • They require a connection to an email client on your customer's machine
  • They send the data with no formatting and it's often difficult to read
  • Mailto forms expose your email address to spammers

If you are still determined to use a mailto form, here are some resources to help:

Improving Your HTML Form Once It's Working

Once you have a tool in place to get your HTML form working, there are a few things you can do to improve the way it works, including validation and spam protection. These are some articles to help you with both.

And for inspiration, you can share the Best Web Forms you've ever seen and see what other forms About.com readers really like.

©2014 About.com. All rights reserved.