in reply to Understanding "Submit" button action

To answer this properly we need to make a distinction first: The form is not part of your perl script. It's just some html that your browser happens to display as text-entry fields and a button. It could have come from anywhere.

When you click on the submit button, the information on the form (in hidden fields and entered by the user) is packaged up into a set of name=value pairs and a request is, er, submitted to the address specified by <form action="...'>.

On receiving the request, the webserver launches the cgi script at the specified address, and makes the supplied bundle of information available to it as part of the environment in which it runs. In perl that information is found in either the $ENV{query-string} variable (if method="GET") or the $ENV{content-length} variable (if method="POST"), the names of which I have probably remembered wrongly because you never need to use them directly. Instead you just use CGI; at the top of your script, and the submitted information is at your fingertips.

I think you're talking about a more complicated case, where there's a series of forms coming from the same script. The short answer is yes: the whole cgi script is invoked each time you submit a form to it. It then does whatever it has to do, returns another form, and exits, only to be called again when that form is submitted.

But what the script has to do with the information submitted each time will vary according to the whim of its author.

One common example: a series of forms that gather more and more data before finally saving the whole lot in a database. The first few times the script runs, all it has to do is send back another form that carries the answers so far in hidden fields and asks some more questions. The last time it runs, it does a big chunk of database work to store all that information and perhaps act on it in some way.

What this probably means is that the whole script is compiled and run with each form submission, including all the equipment for connecting and writing to the database, but often it only has a couple of very simple jobs to do before it exits, and the database machinery is not really needed: all of the script is run each time, but only part of it is used. In this case the last invocation is a lot more expensive than the first few, despite exactly the same script being launched in the same way.

So, er, yes. And no. Unless you're running under mod_perl, in which case, yes no and maybe. Hth.

Replies are listed 'Best First'.
Re: Re: Uderstanding "Submit" button action
by Donnie (Acolyte) on Oct 28, 2002 at 05:26 UTC
    Many thanks to your very detailed replies and explanations. Now I at least I can start to get a handle on what I am trying to do. I appreciate the time taken to so well word your replies. - Blessings