Gossamer Forum
Home : General : Perl Programming :

Would like improve a perl program

Quote Reply
Would like improve a perl program
Hello need help on this program.

What the program does is just a simple form to database using only one .pl file with no externel html or whatsoever. I would like the program to be more modular like the dbman in which I just can paste a new html design of my add form. All I need is the html form(fields) to be more easy to enchance how it will look like.

****the code****

BEGIN
{
use FindBin qw($Bin);
use lib "$Bin";
}#This is for web server so it could find CLI.pm from the current directory

use strict;
use CLI;
use CGI qw(:standard);

print header; # Print "Context-type: text/html"

# print "<HTML>"
# print "<HEAD>User Creation Sample CGI</HEAD>"
# print "<BODY>"
print start_html("User Creation Sample CGI");

if($PostmasterPassword eq "") { # You didn't specify domain/login/password

errormsg("You have to modify the script file to specify the CGPro Server address and Postmaster password");

} elsif(param()) { # The form is already filled
# Read the parameters from the form
my $Account = param("account");
my $RealName = param("realname");
my $Password1 = param("password1");
my $Password2 = param("password2");
my $Age = param("age");
my $City = param("city");
my $Country = param("country");
my $Schcompany = param("schcompany");
my $Altemail = param("altemail");
my $Wheredidyou = param("wheredidyou");
my $BoxType = param("boxtype");

if ($Account eq "") {
errormsg("No account name specified");
}
if ($Password1 eq "") {
errormsg("No account name specified");
}
if ($Password1 ne $Password2) {
errormsg("Passwords do not match!");
}
if ($Age eq "") {
errormsg("Age can't be blank!");
}
if ($City eq "") {
errormsg("City/Province can't be blank!");
}

if ($Country eq "") {
errormsg("Country can't be blank!");
}
if ($Schcompany eq "") {
errormsg("School/Company can't be blank!");
}
if ($Altemail eq "") {
errormsg("Alternative Email can't be blank!");
}

if ($Wheredidyou eq "") {
errormsg("Where Did you find us? can't be blank!");
}




my $cli = new CGP::CLI( { PeerAddr => $CGServerAddress,
PeerPort => 106,
login => $PostmasterLogin,
password => $PostmasterPassword } );
unless($cli) {
errormsg("Can't login to CGPro: ".$CGP::ERR_STRING);
}

my $UserData;
@$UserData{'RealName'}=$RealName;
@$UserData{'Password'}=$Password1;
@$UserData{'Age'}=$Age;
@$UserData{'City'}=$City;
@$UserData{'Country'}=$Country;
@$UserData{'Schcompany'}=$Schcompany;
@$UserData{'Altemail'}=$Altemail;
@$UserData{'Wheredidyou'}=$Wheredidyou;
if($cli->CreateAccount(accountName => $Account,
accountAge => $Age,
accountCity => $City,
accountCountry => $Country,
accountSchcompany => $Schcompany,
accountAltemail => $Altemail,
accountWheredidyou => $Wheredidyou,
accountType => $BoxType,
settings => $UserData)) {
print h1("Account created.");
print a({-href=>'CreateUserCGI.pl'}, 'Create a User');
} else {
errormsg("Can't create account: ".$cli->getErrMessage);
last MAIN;
}
$cli->Logout;

} else { # The form is empty
print h1("Create a user: "),hr();
print start_form();
print p("Account name: ",textfield("account"));
print p("Real name: ",textfield("realname"));
print p("Password: ",password_field("password1"));
print p("Password (again): ",password_field("password2"));
print p("Age:", textfield("age"));
print p("City:",
popup_menu( "city", ['Cavite City','MultiMailbox','MailDirMailbox']));
print p("Country:", textfield("country"));
print p("Schcompany:", textfield("schcompany"));
print p("Altemail:", textfield("altemail"));
print p("Wheredidyou:", textfield("wheredidyou"));
print p("Mailbox type: ",
popup_menu( "boxtype", ['TextMailbox','MultiMailbox','MailDirMailbox']));
print p(submit("Create"),reset("Clear"));
print end_form(),hr();
}
print end_html(); # print"</BODY></HTML>"

sub errormsg { #a procedure to output error message in HTML format and exit
my ($msg) = @_;
print h1("ERROR: $msg");
print a({-href=>'CreateUserCGI.pl'}, 'Create a User');
print end_html();
exit;
}


thanks
Quote Reply
Re: Would like improve a perl program In reply to
One suggestion is to use the DBMAN Template Mod and integrate your script with it.

This Mod is linked in the DBMAN Discussion Forum.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Would like improve a perl program In reply to
Hello!

Maybe you guys can help me put some background colors and center my form field. You can see my non-sense script http://www.digitelone.com/cgi-bin/dbman/CreateUserCGI.pl

I want to use the print qq| something ... is this a reserved word of perl/cgi?
Quote Reply
Re: Would like improve a perl program In reply to
Well for the background color...

1) Add the following variable at the top of the file:

Code:
$bgcolor .= qq|bgcolor="000000"|;

Then find the <BODY> codes in your script...add the above variable to it, like the following:

Code:
<BODY $bgcolor>

2) For the centering of the form...Find the FORM codes <FORM METHOD="" ACTION="">. Put <center> before it and close the center anchor with </center> after the closing tag of the FORM </form>.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: Would like improve a perl program In reply to
Thanks!!! a lot.... i've been experimenting with qq|.


More people like you on earth Smile
Quote Reply
Re: Would like improve a perl program In reply to
You're welcome.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.