On Sat, 23 Oct 2004 10:23:00 +1000, Ron Savage <[EMAIL PROTECTED]> wrote:
> On Fri, 22 Oct 2004 12:40:38 -0400, Drew Taylor wrote:
> 
> Hi Drew
> 
> > In my web apps I follow the common principle of submitting a form
> > back to itself, processing, and then redirecting to a new page. So
> 
> Common principle? Amazing :-). Can you give me a URI for an article discussing this 
> process?

Just google for "avoid form resubmission". :-) You'll find a couple
common thoughts: using javascript to disable the submit button after
the initial click & doing a redirect after processing the form. The
most common case is where a form is creating a new entry in a
database. If you click refresh you resubmit the form and get a
duplicate entry in the database.
 
> I've never needed to get a form to submit itself. I can't understand why such 
> complexity is required, or useful.

I'm not talking about making the html form submit itself (as in
<script>document.form[0].submit();</script>. I'm talking about the
form submitting back to the runmode that displayed it.
 
> Is it because you are talking about error messages, where the form is populated by 
> the app rather than by the user?
> 
> > # is_form_submitted() just looks for the presence of a # hidden
> > param and returns 1/0. if ($self->is_form_submitted) { # process
> > the form...
> 
> Again, under what conditions is the form NOT submitted but still processed?

I guess I didn't make my point. The same runmode both displays the
form and processes said form. See the example code from my original
post. If the hidden param is included the form is processes. If it's
absent the form is simply displayed.

> > # custom method to set redirect headers, etc
> > return $self->redirect($url);
> 
> Sure, there's more than one way etc....
> 
> It's just that I've never needed a redirect in my life. I'm curious as to how you've 
> worked redirects into your way of thinking of them as being part of your solution.

I'm curious how you've handled code that adds a new row in the
database. What do you do to prevent a refresh from adding a duplicate
entry? The redirect is a simple solution that solves a common problem:

You have a form. The user submits it. The app adds a new entry to the
database and displays a page. The user clicks the refresh button. The
form is resubmitted and now you have a duplicate entry.

Drew
-- 
----------------------------------------------------------------
 Drew Taylor                 *  Web development & consulting
 Email: [EMAIL PROTECTED]  *  Site implementation & hosting
 Web  : www.drewtaylor.com   *  perl/mod_perl/DBI/mysql/postgres
 ----------------------------------------------------------------

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

Reply via email to