Re: opening two pages with one html form - using perl




ccc wrote:
How do you submit form data to two separate pages with one html form?

I believe that you would have to use javascript to post to two pages at
the same time .. that I am aware of. However, it depends on what you
want to each page to do. If the second script was just something that
did processing in the background, you could just run the script via
perl's command line interface.


I have one cgi script that looks in part like this:

# name of script is login.cgi
my $login = param('login');
my $username = ('usrname');
my $password = ('password');

if ($login eq 'Login')
{ #authenticate user and log user in if authenticated
} else
{ #display login form, default behavior
}

print <<html;
<form action="login.cgi">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="login" value="Login" />
</form>
html

When the user first arrives here, he gets the login form, enters his
username and password and submits the form. The form returns to the
same script, authententicates the user, and captures the username which
we use for other purposes.

We now have a need to send the script to ANOTHER cgi script, passing
the username, which will open in a new window. In other words, the
login script will exhibit the same behavior as at present, but a SECOND
browser window will open which will display the same username.

Why open into a new window? What is the original page doing after
login?


My first attempt used the javascript window.open() method but that
didn't work, and I don't have any idea for a second attempt.
Suggestions?

The window.open() method should do what you want it to do. Perhaps
you've just not used it right? However, I think you should rethink the
entire way you are doing this. If you open a new window, 9 times out
of 10 the user will have a pop-up blocker. The other time they won't
have javascript enabled.

I think what you want to do .. is use the http header Location and keep
the user in the same page. (imo)


Thanks, CC.

Consider this script:

#!/usr/bin/perl
use CGI;
use strict;

require "functions.pl"; #contains my login functions

my $query=new CGI;
my $form=&_get_parameters($query); #puts the post/get data in a hash
for me
my $log==0;

if($form->{affil} == 1) {
$log=&login_agent($form);
if($log > 0) { print "Location:
members.pl?login=$form->{login}&log=$log\n\n" }

$log=&login_staff($form);
if($log > 0) { print "Location:
staff.pl?login=$form->{login}&log=$log\n\n" }
} elsif($form->{affil} == 2) {
$log=&login_client($form);
if($log > 0) { print "Location:
clients.pl?login=$form->{login}&log=$log\n\n" }
}
print "Location:
index.pl?try=1&login=$form->{login}&affil=$form->{affil}\n\n";

So in this system the user starts at index.pl which contains a form
with 3 fields:
affil = a drop down with Agent==1, Client==2 as the options
login = the user's username
pass = the user's pasword
This form submits to the above script

The functions login_agent, login_staff, and login_client all check the
database for the correct username and password. If it is correct it
sticks a random number in the database in that user's record and
returns this number to the calling program. If the login is invalid,
it returns 0 to the calling program.

The script checks the logins based on the drop-down (notice that staff
members select agent in the drop down). If it finds a valid login it
uses the http header Location to put them into the right system.
Otherwise it sends them back to index.pl which checks the try parameter
and displays a message that they've messed up thier login.

For a while, this is how I did all the logins on my system. Every page
would check the passed login, and log variables against the database.
But I got tired of passing the parameters in every single link I put on
the page. So I started using cookies to store the values. Then to get
even better, I now store a hash of the username w/ the random number
concat on the end.

Just my opinion .. but I wouldn't open new windows right after login.

Hope it helped,
--Chris



--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html


--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html

.



Relevant Pages

  • Re: PHP Protect and select script
    ... You MUST store somewhere the username password combination. ... You post the username/password to the receiving script where you ... you must somehow look up the username password combinations. ... So I don't need to check anything - exept the login name / password ...
    (alt.php)
  • Re: PHP Protect and select script
    ... You MUST store somewhere the username password combination. ... You post the username/password to the receiving script where you ... // In case you want your pages protected, use a session. ... So I don't need to check anything - exept the login name / password ...
    (alt.php)
  • Re: VPN CMAK Login script issue
    ... It seems that when I login to my external workstation under a different ... username and password than username and password I authenticate with through ... I'm not able to map drives and am prompted for a password for each ... >> connects and then runs our login script in sysvol. ...
    (microsoft.public.isa.vpn)
  • opening two pages with one html form - using perl
    ... I have one cgi script that looks in part like this: ... if ($login eq 'Login') ... username and password and submits the form. ... We now have a need to send the script to ANOTHER cgi script, ...
    (comp.infosystems.www.authoring.cgi)
  • Re: Show a login dialog box before the main application
    ... You should do a couple of things, don't allow your login dialog to close ... user enters the correct username and password, ... do that I placed this code in InitInstance but if you click OK 3 times ... without enetring the user name and pwd,the main application window ...
    (microsoft.public.vc.mfc)