[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Redirect question


> I am using CGI::App in a mod_perl environment.  I typically have
> run_modes submit back to themselves for validation, etc.  If the form
> information "passes", I return $self->next_run_mode (just an example).
> I have made a couple of changes to my previous coding style.  First, I
> am using path_info to get the runmode (makes linking and handler
> dispatching much simpler).  Second, because of the first, I want to use
> redirects to move from one run_mode to the next; that is, a form
> submits back to itself and is validated, I do a
> $self->redirect('next_run_mode').  It seems that redirects do not
> conserve the POST information.  Is this true?  If so, does this sound
> familiar to others?  What other coding idioms do people use besides
> submit-to-self?

I think the "submit-to-self, then redirect" method is the cleanest.  Not
always the best performing (because you have two HTTP requests after a
successful submit), but this method creates the fewest problems for
browsers and for your application.

The biggest potential problem is the "double record on refresh" problem:
in a typical CRUD application, after the user successfully creates a
record, they are returned to the list of records.  If they then hit
refresh to update the list, you don't want the form to be resubmitted
and a duplicate record created.

Even if you take steps to avoid this problem (like pre-generating the
record ID in the create form), some browsers will complain when you hit
refresh on a page after a POST.  For instance, MSIE says:

    The page cannot be refreshed without resending the information.
    Click Retry to send the information again, or click Cancel to return
    to the page that you were trying to view.

And if the user hits "cancel" and if you are strict with your cache
headers, MSIE will respond with:

    Warning: Page has Expired
    The page you requested was created using information you submitted
    in a form. This page is no longer available. As a security
    precaution, Internet Explorer does not automatically resubmit your
    information for you.

    To resubmit your information and view this Web page, click the
    Refresh button.

Bleah.

So because of this, I'm trying to follow this rule of thumb:  use POST
for submitting data that changes the state of the application and GET
for requesting pages without changing the app's state.  That's more or
less what the HTTP spec tells you to do anyway, AFAIR.

As I understand it, your main problem with this approach is that
"redirects do not conserve the POST information".  Which POST
information are you trying to conserve?

You can add query params to the redirect URL, so you can pass a small
amount of state information that way.


Michael


--
Michael Graham <suppressed>



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.