Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to pass form data to a onclick=javascript:new.window perl script

by Asgaroth (Novice)
on Feb 17, 2004 at 09:48 UTC ( [id://329544]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

I know this question (or derivatives of it) have been asked before, I found a load in the super search and have tried a couple of the recommendations, but, I always end up coming short. I am 100% positive, there must be something I am missing, but, due to my minimal perl/html/javascript knowledge, I thought I would come to the monestry and seek the wisdom of those who came before....

My setup is as follows:

I have 2 perl scripts,

1 show_page.pl
This script displays a web page and prints a form with 2 "questions" a system name and a message. When the user presses the submit button, a new window opens which "should" run the second script,

2 create_data.pl
This script takes the 2 parameters passed from the above script and converts all text files in a directory to html, displaying output to the new window as it does it (this does not happen though).

Now, the problem I am havin is:

1 When I click on the submit button, the new browser window opens, but my parameters dont appear to have been passed accross to the new script, and, the original window (show_page) executes the 2nd script and displays it in the original window????, an excerpt of my code follows:

1 In show_page.pl

print $front_page -> start_form(-method => 'GET'); print $front_page -> p( $front_page -> code({-align => 'left'}, 'S +ystem\'s fully qualified name (hostname + domain name) ', $front_page -> textfield( -name => 'machine +_name', -size => '40', -default => '', -override => '1' ))); print $front_page -> p( $front_page -> code({-align => 'left'}, 'S +elect the reason for the creation/updating of runbook: ', $front_page -> popup_menu(-name => 'rea +son', -values => ['Sy +stem initial build release','System hardware changed', 'Sys +tem software changed','Daily update for recovery'], -override => '1', -default => 'Sys +tem initial build release'))); print $front_page -> center( $front_page -> submit (-name => 'subm +it', -label => 'Process', -target => 'cr +eate_window', -onClick => "j +avascript:window.open('http://xww.test.com/cgi-bin/cgiwrap/root cgi/create_data.pl','create_window','');void(0)"), $front_page -> reset ());

If I remove the onclick bit, and add an action section to the start_form method to point to the create_data.pl script, all works fine, so I know the scripts (perl) bits appear to be ok, but when I open the new window, I seem to lose my parameters???

Can anyone please help with this coz I'm starting to lose hair with this, I'm sure I am overlooking something so trivial here, that when someone points it out, I will more than likely kick myself (or someone will kick me).

Could it also possibly be that I am going about this in the wrong way, is there any other possible solution to what I am trying todo here??

Thanks
Your humble servent
Asgaroth
  • Comment on How to pass form data to a onclick=javascript:new.window perl script
  • Download Code

Replies are listed 'Best First'.
Re: How to pass form data to a onclick=javascript:new.window perl script
by benn (Vicar) on Feb 17, 2004 at 11:31 UTC
    As Abigail-II says, this is a javascript problem, but I'll bite...:)

    Your parameters need to be read and passed by javascript - they don't exist as CGI values until the form is submitted, and the "window.open" command isn't submitting the form, so you'll need to do something like this, using the DOM's 'value' command...
    window.open('http://xww.test.com/cgi-bin/cgiwrap/rootcgi/create_data.p +l?machine_name=' + document.forms[0].machine_name.value + '&reason=' ++ document.forms[0].reason.value,'create_window','');
    HTH,
    Ben.
      Hi Ben

      Thats it, it worked, thanks a load for the response, I would never have guessed that!!

      Guess thats why I'm at the bottom of the food chain 8)

      Thanks
      Asgaroth
Re: How to pass form data to a onclick=javascript:new.window perl script
by Abigail-II (Bishop) on Feb 17, 2004 at 10:06 UTC
    http://xww.test.com/cgi-bin/cgiwrap/rootcgi/create_data.pl is just a plain request, no query is passed here. Then the URL would be of the form http://xww.test.com/cgi-bin/cgiwrap/rootcgi/create_data.pl?key=value;key=value.

    So, you either have to print that when creating the page, or, if this someway has to be done on the fly, you'd need to find yourself a javascriptmonks site, as the latter option would be a javascript problem, not a Perl problem.

    Abigail

      Hi Abigail-II

      So if I do something like:

      http://xww.test.com/cgi-bin/cgiwrap/rootcgi/create_data.pl?$front_page +->param('machine_name');$front_page->param('reason')

      Do you think that that may pass the parameter's selected by the user, I'm sure those would be set at the point where the user clicks the submit button?

      Thanks
      Asgaroth
        Oops, I made a booboo, the key=value pair, the url would be

        http://xww.test.com/cgi-bin/cgiwrap/rootcgi/create_data.pl?machine_nam +e=$front_page->param('machine_name');reason=$front_page->param('reaso +n')
        Do you think this may work?

        Thanks
        Asgaroth
Re: How to pass form data to a onclick=javascript:new.window perl script
by Lori713 (Pilgrim) on Feb 17, 2004 at 20:38 UTC
    Hi Asgaroth,

    I, too, ran across this issue, but in my case I wasn't launching new windows. For me, I ended up using a hidden field, concatenating my variables, and stuffing them inside a TMPL_INCLUDE that I was using for HTML::Template. I was using the POST method (plus I needed to manipulate some of the variables in the next .pl that was called) for various nefarious purposes.

    benn's idea is great for when I set up my scripts to launch new windows. benn++

    Lori

Re: How to pass form data to a onclick=javascript:new.window perl script
by kutsu (Priest) on Feb 17, 2004 at 21:31 UTC

    I would like too caution you, and any others who might look at this code, that this code would pass data in an unsecure manner. If it is sensitive data you might encrypt it before you send it, though encryption still doesn't ensure security. If you'd like to know more about encryption Ovid's cgi course has an example, and for security check the Security Faq and Ovid's Cgi-course

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Re: How to pass form data to a onclick=javascript:new.window perl script
by exussum0 (Vicar) on Feb 17, 2004 at 10:56 UTC
    I don't write JS all the time, but I know that you can create a form with hidden fields, and have your function do a form.submit(). It doesn't use the CGI module, but it does avoid the ugly get method.
    <html> <body> <form name="myform" action="http://perlmonks.org/index.pl?" method="po +st"> <input type="hidden" name="node" value="sporty"> </form> <a href="#" onClick="myform.submit()">clicky!</a> </body> </html>
    I did this using safari. Try it in moz, try it in ie.

    Update: Case of morning eyes. I read through the thread forgetting it was "new window".


    Play that funky music white boy..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://329544]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-24 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found