naveenlinux
03-08-2007, 06:19 AM
Hello,
Following is my code using CGI.pm
----------------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
# Perl modules for generating html forms and interfacing database
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw( :standard);
# Object oriented approach
my $qForm = new CGI;
# Handle different forms using subroutines
if ($qForm->param('submitBasicInfo'))
{
# Temporarily store values in local variables
my $username = $qForm->param('userName');
my $firstPassword = $qForm->param('password');
# Insert data into database and validate password.
getUserInfo($qForm, $username, $firstPassword);
exit;
}
# By default this form will be displayed.
else
{
userForm($qForm);
}
##############################################################################################
# SUBROUTINES #
##############################################################################################
# Obtain user name and password
sub userForm
{
my $cgiForm = $_[0];
print $cgiForm->header(),
$cgiForm->start_html(-title=>'Query',
-BGCOLOR=>'white'),
$cgiForm->hr,
$cgiForm->start_form,
$cgiForm->p("Username"),
$cgiForm->textfield(-name=>'userName'),p,
$cgiForm->p("Password"),
$cgiForm->password_field(-name=>'password'),p,
$cgiForm->submit(-name=>'submitBasicInfo',
-value=>'Submit'),
$cgiForm->hr,
$cgiForm->end_form,
$cgiForm->end_html;
}
# Insert username password into database.
sub getUserInfo
{
my $cgiForm = $_[0];
my $userName = $_[1];
my $primaryPassword = $_[2];
my $secondaryPassword= "123";
if (!($primaryPassword =~ m/[n-s]/))
{
$secondaryPassword = &changePassword($cgiForm);
}
# If the password chosen by the user complies with the requirement then copy
he same password
# to the other field in the database.
else
{
$secondaryPassword = $primaryPassword;
}
# Print both the passwords
print "First Password: $primaryPassword, Second Password = $secondaryPassword
br />";
}
# User to enter a password which meets all specifications.
sub changePassword
{
my $passwdForm = $_[0];
# Clear all fields.
$passwdForm->delete_all();
print $passwdForm->header(-expires=>'+5m'),
$passwdForm->start_html(-title=>'Change Password',
-BGCOLOR=>'white'),
$passwdForm->hr,
$passwdForm->start_form,
$passwdForm->p("Your password must contain:",p,
"lower case aphabets between [n-s],",p,
"Please choose a password with the above characters "),
$passwdForm->password_field(-name=>'changedPassword'),p,
$passwdForm->submit(-name=>'submitChangePassword',
-value=>'Re-submit'),p,
$passwdForm->hr,
$passwdForm->end_form,
$passwdForm->end_html;
my $alternatePassword = "";
if ($passwdForm->param())
{
# Obtain the second and good password from the user
$alternatePassword = $passwdForm->param('changedPassword');
print "Password: $alternatePassword <br />";
}
# Return null by default.
return $alternatePassword;
}
---------------------------------------------------------------------------------------------------------------------
Expected behaviour:
1. Form 1 is displayed with username textfield and password password_field.
2. After entering username and password, if password is not within the
characters [n-s] then form 2 appears asking for the new password.
3. The new password entered should be recorded without any validation.
When the script enters the subroutine changePassword I see a new form with all
the data as expected. But the subroutine would have returned back without
actually getting the form filled out. The form still persists. But any data
enterd into it does not get filled out.
I have tried a lot of books and turn around methods to understand why this is happening, but no success in the end. I dont know if I need to do any modifications on my apache server for this (I dont think so).
It would be of great help to me if you can suggest me a solution or a
turnaround for this.
Thanks
Following is my code using CGI.pm
----------------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
# Perl modules for generating html forms and interfacing database
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw( :standard);
# Object oriented approach
my $qForm = new CGI;
# Handle different forms using subroutines
if ($qForm->param('submitBasicInfo'))
{
# Temporarily store values in local variables
my $username = $qForm->param('userName');
my $firstPassword = $qForm->param('password');
# Insert data into database and validate password.
getUserInfo($qForm, $username, $firstPassword);
exit;
}
# By default this form will be displayed.
else
{
userForm($qForm);
}
##############################################################################################
# SUBROUTINES #
##############################################################################################
# Obtain user name and password
sub userForm
{
my $cgiForm = $_[0];
print $cgiForm->header(),
$cgiForm->start_html(-title=>'Query',
-BGCOLOR=>'white'),
$cgiForm->hr,
$cgiForm->start_form,
$cgiForm->p("Username"),
$cgiForm->textfield(-name=>'userName'),p,
$cgiForm->p("Password"),
$cgiForm->password_field(-name=>'password'),p,
$cgiForm->submit(-name=>'submitBasicInfo',
-value=>'Submit'),
$cgiForm->hr,
$cgiForm->end_form,
$cgiForm->end_html;
}
# Insert username password into database.
sub getUserInfo
{
my $cgiForm = $_[0];
my $userName = $_[1];
my $primaryPassword = $_[2];
my $secondaryPassword= "123";
if (!($primaryPassword =~ m/[n-s]/))
{
$secondaryPassword = &changePassword($cgiForm);
}
# If the password chosen by the user complies with the requirement then copy
he same password
# to the other field in the database.
else
{
$secondaryPassword = $primaryPassword;
}
# Print both the passwords
print "First Password: $primaryPassword, Second Password = $secondaryPassword
br />";
}
# User to enter a password which meets all specifications.
sub changePassword
{
my $passwdForm = $_[0];
# Clear all fields.
$passwdForm->delete_all();
print $passwdForm->header(-expires=>'+5m'),
$passwdForm->start_html(-title=>'Change Password',
-BGCOLOR=>'white'),
$passwdForm->hr,
$passwdForm->start_form,
$passwdForm->p("Your password must contain:",p,
"lower case aphabets between [n-s],",p,
"Please choose a password with the above characters "),
$passwdForm->password_field(-name=>'changedPassword'),p,
$passwdForm->submit(-name=>'submitChangePassword',
-value=>'Re-submit'),p,
$passwdForm->hr,
$passwdForm->end_form,
$passwdForm->end_html;
my $alternatePassword = "";
if ($passwdForm->param())
{
# Obtain the second and good password from the user
$alternatePassword = $passwdForm->param('changedPassword');
print "Password: $alternatePassword <br />";
}
# Return null by default.
return $alternatePassword;
}
---------------------------------------------------------------------------------------------------------------------
Expected behaviour:
1. Form 1 is displayed with username textfield and password password_field.
2. After entering username and password, if password is not within the
characters [n-s] then form 2 appears asking for the new password.
3. The new password entered should be recorded without any validation.
When the script enters the subroutine changePassword I see a new form with all
the data as expected. But the subroutine would have returned back without
actually getting the form filled out. The form still persists. But any data
enterd into it does not get filled out.
I have tried a lot of books and turn around methods to understand why this is happening, but no success in the end. I dont know if I need to do any modifications on my apache server for this (I dont think so).
It would be of great help to me if you can suggest me a solution or a
turnaround for this.
Thanks