The Wayback Machine - https://web.archive.org/web/20080829194346/http://www.webreference.com/html/tutorial30/5.html


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
Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Oops! I Fixed the Linux Kernel

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.

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.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.

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/



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Performance Optimizations for High Speed JavaScript · Advanced Web Performance Optimization · Simple Comments Meets OpenID
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Extending Telephony: VoIP Call Recording for Business · U-Verse for Business Has Wi-Fi Perks · Lian-Li Launches New Power Supply Line, Rack Mount Kit and Fan Blower

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

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.