...

View Full Version : post form page again.



hongyi
08-20-2002, 09:32 AM
When the user input something on a perl form page and there is an error, for example, userid already exists. How do i display the error message: "UserID already exist" and at the same time display the form page again???

Pls help......

andy7t
08-20-2002, 12:42 PM
Theres not really an easy quick way to do this.
What you can do is:

#!/usr/bin/perl


print "Content-type: text/html\n\n";


read(STDIN,$indata,$ENV{'CONTENT_LENGTH'});
@indata = split(/&/,$indata);
foreach $i (0..$#indata)
{
$indata[$i] =~ s/\+/ /g;
($key,$val) = split(/=/,$indata[$i],2);
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$indata{$key} .= "\0" if (defined($indata{$key}));
$indata{$key} .= $val;


}
if( -e "$indata{'userid'}")
{
print("Error. Userid Already Exists\n");
$error = "userid";
}
#THIS IS YOUR FORM
print("
<form action=page.cgi method=post>
Name: <input type=text name=name size=25>\n"); if($error eq "name")print("Name incorrect\n");
print("Userid: input type=text name=userid size=25>\n"); if($error eq "userid")print("Userid incorrect\n");

print("Password: input type=text name=password size=10>\n"); if($error eq "password")print("Password incorrect\n");


<input type=submit value=Signup>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum