Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Perl CGI redirect

by poj (Priest)
on Apr 17, 2013 at 15:53 UTC ( #1029172=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Perl CGI redirect
in thread Perl CGI redirect

Not sure about multiple servers but to open a new page you can do it with some javascript. I have added the javascript to a new clickme button as an example.

#!/usr/bin/perl # n.cgi use strict; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser ); use POSIX qw(strftime); my $today = time; my $yesterday = $today - 60 * 168 * 60; my $FM = strftime "%m-%d-%Y", ( localtime($yesterday) ); my $TM = strftime '%m-%d-%Y', localtime; # page layout my $page =<< "EndOfText"; <h2>Add Logical:</h2> <form name="form" method="post" action="n.cgi"> <table> <tr> <td align="right"><strong>Logical:</strong></td> <td> <textarea id="ta" name="server" rows="1" cols="30" wrap="soft"></te +xtarea> </td> </tr> <tr> <td colspan="2"> &nbsp; </td> </tr> <tr> <td> <button type="button" onClick="javascript:clickme()">Click Me</ +button></td> <td> <input type="submit" name="action" value="Search" /> </td> </tr> </table> </form> EndOfText # construct URL my $URL = 'http://a.com:8080/bms/healthMonitor.do?method=redirect' .'&operation=BackupHistorySearch' .'&subOperation=GetReport' ."&fromDateStr=$FM&toDateStr=$TM"; # javascript my $JSCRIPT=<<EOF; function clickme(){ var URL = \'$URL\' + '&clientName=' + document.getElementById("ta").value // comment out if or remove when working OK if (confirm(URL)==true) { window.open(URL) }; } EOF # get parameters my $q = CGI->new; my $action = $q->param('action'); my $server = $q->param('server'); # add server $URL .= "&clientName=$server"; # redirect if required if ($action eq 'Search'){ # remove hash to redirect print $q->redirect($URL); } else { print $q->header, $q->start_html( -title => "Some Title", -script=> $JSCRIPT), $page, $q->end_html; }
poj


Comment on Re^4: Perl CGI redirect
Download Code
Re^5: Perl CGI redirect
by Anonymous Monk on Apr 17, 2013 at 19:59 UTC

    Thanks for the response. However this adds the client to the end of the URL instead of adding it to place listed as XXXX. I tried to specift $ta, however it fails with the below error my $URL = "http://a.com:8080/bms/healthMonitor.do?method=redirect&operation=BackupHistorySearch&subOperation=GetReport&clientName=XXXX&fromDateStr=$FM&toDateStr=$TM"; Wed Apr 17 15:43:03 2013 n.cgi: Global symbol "$ta" requires explicit package name at ./n.cgi line 42. Wed Apr 17 15:43:03 2013 n.cgi: Execution of ./n.cgi aborted due to compilation errors.

      The parameter order should not normally matter but if it does just revise the javascript as follows
      my $JSCRIPT=<<EOF; function clickme(){ var URL = 'http://a.com:8080/bms/healthMonitor.do?method=redirect' + '&operation=BackupHistorySearch' + '&subOperation=GetReport' + '&clientName=' + document.getElementById("ta").value + '&fromDateStr=$FM&toDateStr=$TM' // comment out if or remove when working OK if (confirm(URL)==true) { window.open(URL) }; } EOF
      poj

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029172]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-28 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls