3

I often design step-by-step processes (i.e. Shopping Cart) in the following way:

  1. Form posts to itself
  2. On post, validate entries.
  3. If NOT valid, display the form with error messages.
  4. If valid, save the entries (to SESSION or database, etc.), then send the user to the next step/page using <CFLOCATION />.

My question is, is this the proper use of <CFLOCATION />? Looking at the definition for this tag, it seems that it should be used for actual "moved files", considering it sends an HTTP Header Response Code by default, and allows you to enter another, if needed.

In my case, there's no "moved files", I simply want to send the user to another page after they've completed a task. If someone were to look at the IIS logs, it could be very misleading, seeing a bunch of 301s.

I'm just looking for a best practice principle here, assuming I cannot re-engineer the whole process to use AJAX.

Eric Belair
  • 10,574
  • 13
  • 75
  • 116
  • 2
    That is a perfectly acceptable use of cflocation. No different, really, than redirecting a user to a login form if they are not yet logged in. – Scott Stroz Jul 25 '13 at 17:00
  • 5
    one thing to note - make sure you use `addToken="false"` so it doesn't add the `cfID` and `cfToken` to the url for each page. – Matt Busche Jul 25 '13 at 17:06

1 Answers1

5

Seems fine to me. CFLocation does a 302 redirect by default, so it's fine for temporary redirects. Unless you're specifying 301 for the statusCode?

duncan
  • 31,401
  • 13
  • 78
  • 99