Frankie has asked for the wisdom of the Perl Monks concerning the following question:

I need to call a PERL script from a remote form on submission ... picking up some information from the form. My choices are to use a pure 'redirect' to and from my script or to use Javascript to call the Perl module. I'm not returning anything back to Javascript ... just sending the information as parameters ... something like .. $mylink = http://www.mysite.com/cgi-bin/perlscript.pl?f=foo&b=bar Once I get this, I can check the environment variable to identify the redirect string, pluck off the parameters and life is great ... Problem is, I have no clue how to write the JavaScript to "ping" my PERL script without trying to open it up as a page, i.e. window.open($mylink); This has got to be easy ... but I'm googled out. Any ideas? Thanks in advance. FH

Replies are listed 'Best First'.
Re: I know this should be easy but ...
by dws (Chancellor) on Aug 14, 2002 at 22:39 UTC
    I need to call a PERL script from a remote form on submission ... picking up some information from the form.

    I'm not clear on what you're trying to achieve. Are you trying to do the equivalent of two separate POSTs from one form?

    It might be simpler to implement a CGI that front-ends another CGI. That is, your CGI captures the form, then makes a LWP post to a second script, returning the results to through your script and back to the browser.

    The appeal of this approach is that it doesn't depend on client-side Javascript.

      Thanks for the replies. FormMail autogens an email from a form submission ... not quite what I have in mind although it's a possible workaround.

      You're right about the equivalent of two separate POSTS ... the form action would be something like "return Form_Validator(this);" calling a JavaScript function that validates the form fields are complete, checks the text, etc. AND would ping my PERL script.

      That way, I can avoid redirecting from one form to another across the wire.

      Everything I can read about JavaScript indicates that if you're going to hit a URL, you're going to open a page whether you want to or not, I don't want to ... just ping the script.
        > calling a JavaScript function that validates the form fields are complete, checks the text, etc. AND would ping my PERL script

        Maybe I'm missing something here ... is there any reason you can't just validate the required fields using JS (spitting out the JS whatever when a field isn't complete), and as long as there's no problems, submit the form via CGI as a POST request?
Re: I know this should be easy but ...
by tstock (Curate) on Aug 14, 2002 at 23:22 UTC
    You can have a CGI script return status code 204, do nothing. If you're using CGI.pm, the syntax is something like:
    print $query->header(-status=>'204 No response');

    I have done this from javascript to post things to the server without expecting a return.

    Tiago
Re: I know this should be easy but ...
by rob_au (Abbot) on Aug 14, 2002 at 22:36 UTC
    Although, it sounds like you might be a little confused as to how the HTTP client interacts with server-side CGI scripts, I think a good start would be to have a look at NMS collection of scripts. One of these scripts, FormMail, would provide the form submission functionality that you require and could easily be configured to redirect the HTTP client back to a page or URL of your choice.