
Cretep
User
Jun 3, 2000, 8:03 PM
Post #3 of 3
(2055 views)
|
Hi This should do the trick. This has only taken me fifteen minutes or so and has been tested. I am more that happy to modify it to further suit your needs. If you have any problems setting it up just post the problem to this forum or to my email address. #!/usr/bin/perl # Change the above path to suite your server # Petition script. Free to use by any one. No credit needed and absolutely no copyright imposed!! # by Peter Crouch # Email: woodduck@bigpond.com # URL: http://www.perlbay.com $database = "names.txt"; # The names are stored here $script_name = "petition.cgi"; # The name of the script &phrase_input; &action; end; sub phrase_input { read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); 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; $FORM{$name} = $value; } } sub action{ if ($FORM{'action'} eq "add"){ &add; }else { &form; } } sub form { # You can modify any of the HTML in here however leave the form alone print "Content-type: text/html\n\n"; print qq~ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Please sign our petition</title> </head> <body body="#ffffff" text="#000000" link="#0000ff" alink="#ff0000" vlink="#0000ff"> <font face="verdana" size="-1">Please sign our petition.</font> <form action="$script_name" method="post"> <input name="action" type="hidden" value="add"> <table> <tr> <td><font face="verdana" size="-1">Your Name:</font></td> <td><input name="name" type="text" value=""></td> </tr><tr> <td colspan="2" align="center"><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html> ~; } sub add { open (ADD,">>$database") | | die "Error opening the database -\n $!\n"; flock ADD, 2; print ADD "$FORM{'name'}\n"; flock ADD, 8; close(ADD); &response; } sub response { print "Content-type: text/html\n\n"; # You can modify any of the HTML in here. print qq~ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Thank you for signing our petition</title> </head> <body body="#ffffff" text="#000000" link="#0000ff" alink="#ff0000" vlink="#0000ff"> <font face="verdana" size="3">Your name has been added to our petition. Thank you.</font> </body> </html> ~; } Good luck Peter Crouch [This message has been edited by Cretep (edited 06-03-2000).]
|