in reply to onSubmit Redirect

I'm a little unclear as to what you are trying to achieve, but it looks like you want to submit the form data to two seperate scripts, only one of which returns something useful to the user.

Forget about "onsubmit", using client side scripting is unreliable at the best of times, and I don't think it can solve your problem anyway. The standard (and the only really safe) technique to do this is to:

  1. Submit the form to one script - specified in the action attribute of the form
  2. Have that script return a 302 (meaning Found) status in its http header along with a Location header that redirects the user agent to the next script in sequence. As you are working with a GET request you will have to build the URL to the second script programatically so you can include the submitted data.
  3. Have the second script return a suitable http header and the HTML document.

If you need to decide which script to process the data with depending on a user selection in the form (including the clicking of a specific submit button) you can check the value of the parameter in the first script and use that to decide which (if any) other script to redirect to (i.e. what to specify after Location in the headers).

(As a side note, when writing HTML (not HTTP headers) ampersand characters (&) must be escaped as (&) except under certain circumstances, which the above data doesn't fall under, when the escaping is optional)

Replies are listed 'Best First'.
Re^2: onSubmit Redirect
by hok_si_la (Curate) on Feb 04, 2005 at 19:49 UTC
    First of all I thank both of you for your responses. Sorry I am just now responding. I was at lunch.

    I am passing all of the form element data to the script changestatus.pl. That script will open up a DBI session and update all the table columns. The URL literally contains about a paragraph of information. Real long story there. I originally had this at the bottom of changestatus.pl

    ########################################################### sub printDone ############################################################ { my $url = "http://nettools/NewServer/scripts/adminrequests.pl"; print "Location: $url\n\n"; }

    That worked out fine. The problem is that I now want the user to be redirected to a script (getlist) that lists all of the updated information. This script uses a tab function that I wrote which is why it needs cgi passed to it that would make any of Tolkien's works look like Cliff Notes.

    I have considerred three methods of doing this.
    1)Just use the code above but figure a way of going back 2 listings in the browser history.
    2)Pass all of the necessary variables (those in $action) to changestatus.pl and make the changes to the function above.
    3)Run a script while redirecting to the complicated URL I gave earlier. (Hardcoded equivelent to a history.go(-2)).This would be done using print redirect or something similar when the submit button is clicked.

    I hope that clarifies the situation. Essentially it would be best if I could figure out a way to accomplish method 3, but if not, I can find a workaround using one of the first two ideas.

    Thanks again,
    Shane