spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 30 / 5

index1234567

HTTP for HTML Authors, Part III

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Responding to form submission

Now that we've covered the methods used when submitting a form in an HTTP request, the question that begs itself is what do we do about the response we send back?

Most of the time, the standard 200 OK code is appropriate. Usually it means that whatever request the form submission made was fulfilled and the resulting document is the result or confirmation of this action.

There are a couple of other responses you might want to use however. If the submission causes some resource to be created, you might want to use the 201 Created status code together with the Location header to redirect the user to the resource. This will usually be in response to a POST query. For instance, let's assume that a user of a Web-based forum posts a message to a discussion board through a form. The response could be something like this:

HTTP/1.1 201 Created
Location: http://www.acme.com/forum/messages/2001-03-15/20034559
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html40/strict.dtd">
Message created

Your message has been posted

If you're less fussy about space than I am in this last example you'll probably be more creative with the document you send along confirming the message creation, but you get the idea. The user agent should redirect the user to the location of the created resource immediately. Some older browser's don't support this, while others might opt to wait for the user to confirm the redirection, which is why we also supply a document confirming the creation.

Another useful code is 202 Accepted. This status code implies that the form data has been accepted for processing, but nothing has happened because of it. The body of the response should contain a document which explains that the data has been received and will soon be acted on upon, perhaps linking to a URL that will tell the user how his request is progressing.

HTTP/1.1 202 Accepted
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html40/strict.dtd">
Message accepted

Your message has been accepted and will be posted shortly.

The above response is typical of a 202 Accepted requested, though once again you might want to work on the HTML a bit.

index1234567

Next Page...

http://www.internet.com/

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

URL: http://www.webreference.com/html/tutorial30/5.html

Produced by Stephanos Piperoglou
Created: March 15, 2001
Revised: March 16, 2001