Learning Resources
Form Processing
There are two sides to form processing: the client-side and the server-side.
The client-side is the actual form that a visitor sees on your Web page. The form accepts the information entered by the user and the browser sends the data to the server for processing.
The server-side is a little more complicated, mainly because you have so many options for form processing. When the browser sends the form data to the server, it (the browser) assumes the server knows what to do with it. The server relies on you, the webmaster, to provide those instructions.
If you don't, the user may see an error message. Even worse, the form may seem to submit without a problem, but nothing really happens on the server-side. Keep this from happening by becoming familiar with the attributes that go with the FORM tag, what they mean, and what they do.
What is the ACTION attribute?
The ACTION attribute specifies the URL that will receive and process the form data. Use ACTION to send the form to a processing script or to email the form data, like this:
-
CGI Script: action="https://www.SiteName.com/cgi-bin/processForm.cgi."
This sends the form data to a CGI script that writes the information to a database or saves it in some format.
-
JavaScript function: action="javascript:functionName()"
This fires a JavaScript function that includes form handling information. Careful with this one: if visitors have JavaScript turned off or are using non-JavaScript browsers like screen readers, your form won't process at all.
-
Email: action="mailto:[email protected]"
Webmasters often use a MAILTO in the ACTION attribute to automatically subscribe people to mailing lists or listservers.
The ACTION attribute defines how the form will be processed and the method attribute defines how the form data will be sent. Use METHOD to tell the browser which HTTP method to use to submit the form data.
METHOD has two possible values: GET and POST.
With POST, you send the contents of the form as a data stream. Form data sent using GET becomes part of the URL.
POST separates the form data from the URL and includes it in another part of the HTTP request to the server. JavaScript functions and many CGI scripts that process forms require you to use the POST method.
Although GET is the default, it's an older method that's deprecated (marked for deletion in future HTML versions) in HTML 4.0.
POST is often the preferred way to send information especially if it's sensitive data or contained in a particularly long form.