CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
form checker

 



benjaminlawrie
Deleted

Nov 7, 2000, 8:07 AM

Post #1 of 12 (4273 views)
form checker Can't Post

need a script that will parse through a form for forced entries and then store one copy in a flatfile database and send the other on as per normal formail script.
I would also like the script to be able to check within the database for existing entries so people cannot submit the same peice of information, in this case so as not to have two people with the same username.


sleuth
Enthusiast

Nov 7, 2000, 11:54 AM

Post #2 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
If you post a form with all of the fields and text next to each field letting me know what there for then I'll write the code to do that, and explain it to you.

Better yet if you could just make a page that'd be great.

Sleuth


benjaminlawrie
Deleted

Nov 7, 2000, 4:53 PM

Post #3 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

when you say a page i asume you mean the html page which submits the information, if so heres the html:

<form action="http://www.form.url.cgi" method="POST">
<div align="center"><center><table
BORDER="0" CELLPADDING="0">
<tr>
<td><div align="right"><p><font face="tahoma,arial,helvetica" size="1">Choose username:</font></td>
<td><small><input NAME="User name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td><div align="right"><p><font face="tahoma,arial,helvetica" size="1">First Name:</font></td>
<td><small><input NAME="first name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td><div align="right"><p><small><small>Last name:<small> :</small></small></small></td>
<td><small><input NAME="last name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td><small><div align="right"><p><small>Password: </small></small></td>
<td><small><input type="text" name="PASSWORD" size="20"></small></td>
</tr>
<tr>
<td><small><small><div align="right"><p>email address: </small></small></td>
<td><small></small><input type="text" name="email " size="20"><small></small></td>
</tr>
</table>
</center></div><div align="center"><center><p><br>
<br>
<input TYPE="submit" VALUE="submit"></p>
</center></div>
</form>

sorry if my html is a bit wrong!


sleuth
Enthusiast

Nov 8, 2000, 2:37 PM

Post #4 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
Sorry I'm taking so long mate,

I'll have it done for you very soon.

Your html is fine, did you write it out? If so you should look into an editor.

Sleuth


sleuth
Enthusiast

Nov 9, 2000, 11:17 PM

Post #5 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
Ta da, Here it is, I had a busy day sorry for lateness,

New html:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<body>
<p>
<form action="http://station2/cgi-bin2/test.cgi" method="POST">
<div align="center"><center><table
BORDER="0" CELLPADDING="0" width="365">
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Choose username:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input NAME="user" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>First Name:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input NAME="first_name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Last name:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input NAME="last_name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Password:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input type="text" name="PASSWORD" size="20"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>email address:</b></font></td>
<td width="14"></td>
<td width="152"><small></small><input type="text" name="email" size="20"><small></small></td>
</tr>
</table>
</center></div><div align="center"><center><p><br>
<br>
<input TYPE="submit" VALUE="submit"></p>
</center></div>
</form>
</body>
</html>


END:

And code:


print "Content-type: text/html\n\n";
use CGI qw/:standard :html3/;
$data = 'C:\Inetpub\wwwroot\cgi-bin2\test.db';
$user = param('user');
$first_name = param('first_name');
$last_name = param('last_name');
$email = param('email');
$password = param('password');
$ok_message = qq~
<p align="center">Your Information Was Successfully Added</p>
~;
$notok_message = qq~
<p align="center">Sorry, That User Name Already Exists.
<br><br><a href = "javascript:history.go(-1);">Back</a>
</p>
~;
$error_message = qq~
<p align="center">Please Fill out all the required fields.
<br><br><a href = "javascript:history.go(-1);">Back</a>
</p>
~;
$bademail_message = qq~
<p align="center">Please Submit A Valid Email address.
<br><br><a href = "javascript:history.go(-1);">Back</a>
</p>
~;
if (!$user &#0124; &#0124; !$first_name &#0124; &#0124; !$last_name &#0124; &#0124; !$email &#0124; &#0124; !$password){
print "$error_message";
exit;
}
if ($email !~ m,.*?\@.*?\.(.*),){
print "$bademail_message";
exit;
}
if (-e "$data"){}else{
open(make, ">$data");
print make "";
close(make);
}
open(file, "<$data");
while(<file> ){
(@res)=split(/\|\^\|/, $_);
if ($res[2] eq "$user"){
$dontadd = "1";
}
}close(file);
if (!$dontadd){
open(data, ">>$data");
print data "$first_name|^|$last_name|^|$user|^|$password|^|$email|^|\n";
close(data);
print "$ok_message";
}else
{
print "$notok_message";
}


I can also email it to you if you want in a zip file.

I did this on my pc, so the path is th C:\, you can change that easily.

Sleuth


sleuth
Enthusiast

Nov 9, 2000, 11:21 PM

Post #6 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
Umm, installation, lol

Just upload it, chmod to 755, of course, and then point the html to the proper addy, then give the $data var the path to the file you want it to use. You can use local path by just putting a name, like "people.db", and that's it, once you give $data var a path, it will creat it for you and you can start building it up or whatever.

Sleuth


benjaminlawrie
Deleted

Nov 10, 2000, 2:49 PM

Post #7 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

Hi!
Thanks for your help but it doesn't seem to work!
I tried adding the path to perl but seems to have had no effect.
This is what it said in the log files:
[Fri Nov 10 23:36:18 2000] [error] (8)Cannot run a file that does not have a valid format.: exec of /host/w/w/w/t/h/e/www.thebyp.net/cgi-bin/pops.cgi failed
[Fri Nov 10 23:36:18 2000] [error] [client 64.209.134.133] Premature end of script headers: /host/w/w/w/t/h/e/www.thebyp.net/cgi-bin/pops.cgi
syntax error at /host/w/w/w/t/h/e/www.thebyp.net/cgi-bin/pops.cgi line 28, near "| |"
syntax error at /host/w/w/w/t/h/e/www.thebyp.net/cgi-bin/pops.cgi line 31, near "}"
Execution of /host/w/w/w/t/h/e/www.thebyp.net/cgi-bin/pops.cgi aborted due to compilation errors.
[Fri Nov 10 23:37:45 2000] [error] [client 64.209.134.133] Premature end of script headers: /host/w/w/w/t/h/e/www.thebyp.net/cgi-bin/pops.cgi

Any help appriciated.


sleuth
Enthusiast

Nov 10, 2000, 2:56 PM

Post #8 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
Windows98/95/me or NT, or are you on a linux server?

Sleuth


benjaminlawrie
Deleted

Nov 10, 2000, 3:09 PM

Post #9 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

its unix
if you go to http://www.thebyp.net/cgi-bin/perldiver.cgi
it will tell you just about anything you could want to know about the server.

cheers again!


sleuth
Enthusiast

Nov 10, 2000, 8:32 PM

Post #10 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
Ok, I'll change it accordingly.

Sleuth


benjaminlawrie
Deleted

Nov 11, 2000, 2:15 AM

Post #11 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

Thanks alot for your help. It's much appriciated.


sleuth
Enthusiast

Nov 11, 2000, 2:08 PM

Post #12 of 12 (4273 views)
Re: form checker [In reply to] Can't Post

 
Ok, Sorry about that, I got you mixed up with someone else who was on windows and I wrote it for win32 platforms.

But here it is. Just edit my message and you can cut & paste it really easily.


<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



#!/usr/bin/perl
########################################################################################################################################################################
sub parse_form {
my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
&cgierr('You cant run this script from telnet/shell.');
}

PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

($value eq "---") and next PAIR;
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);
}
return %in;
}


########################################################################################################################################################################
%in =&parse_form;
print "Content-type: text/html\n\n";
$data = "test.db";
$user = $in{'user'};
$first_name = $in{'first_name'};
$last_name = $in{'last_name'};
$email = $in{'email'};
$password = $in{'password'};
$ok_message = qq~
<p align="center">Your Information Was Successfully Added</p>
~;
$notok_message = qq~
<p align="center">Sorry, That User Name Already Exists.
<br><br><a href = "javascript:history.go(-1);">Back</a>
</p>
~;
$error_message = qq~
<p align="center">Please Fill out all the required fields.
<br><br><a href = "javascript:history.go(-1);">Back</a>
</p>
~;
$bademail_message = qq~
<p align="center">Please Submit A Valid Email address.
<br><br><a href = "javascript:history.go(-1);">Back</a>
</p>
~;
if (!$user &#0124; &#0124; !$first_name &#0124; &#0124; !$last_name &#0124; &#0124; !$email &#0124; &#0124; !$password){
print "$error_message";
exit;
}
if ($email !~ m,.*?\@.*?\.(.*),){
print "$bademail_message";
exit;
}
if (-e "$data"){}else{
open(make, ">$data");
print make "";
close(make);
}
open(file, "<$data");
while(<file> ){
(@res)=split(/\|\^\|/, $_);
if ($res[2] eq "$user"){
$dontadd = "1";
}
}close(file);
if (!$dontadd){
open(data, ">>$data");
print data "$first_name|^|$last_name|^|$user|^|$password|^|$email|^|\n";
close(data);
print "$ok_message";
}else
{
print "$notok_message";
}

</pre><HR></BLOCKQUOTE>


The html has to be like this.


<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<body>
<p>
<form action="http://www.site.com/test.cgi" method="POST">
<div align="center"><center><table
BORDER="0" CELLPADDING="0" width="365">
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Choose username:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input NAME="user" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>First Name:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input NAME="first_name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Last name:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input NAME="last_name" TYPE="text" SIZE="20,1" MAXLENGTH="100"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>Password:</b></font>
</div>
</td>
<td width="14"></td>
<td width="152"><small><input type="text" name="PASSWORD" size="20"></small></td>
</tr>
<tr>
<td width="189"><div align="right"><p><font face="Verdana" size="2"><b>email address:</b></font></td>
<td width="14"></td>
<td width="152"><small></small><input type="text" name="email" size="20"><small></small></td>
</tr>
</table>
</center></div><div align="center"><center><p><br>
<br>
<input TYPE="submit" VALUE="submit"></p>
</center></div>
</form>
</body>
</html>


</pre><HR></BLOCKQUOTE>


Ok, so try that now, It should work on any unix system, The other one used a module you may not have.

Sleuth

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives