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: Perl Programming Help: Beginner:
Using cookies to auto fill HTML Form fields

 



dspent001
Deleted

Dec 18, 2000, 11:12 PM

Post #1 of 3 (658 views)
Using cookies to auto fill HTML Form fields Can't Post

Ok, the question is advanced, but my knowledge isnt, in fact I haven't the slightest idea about how to program in perl....so go easy!

How can I set a cookie to store an email address, so that I can then call the cookie to automatically fill in html fields.

An example of this would be a user loging into a standard cgi password script that controls access to my members area, once authorised they could access the site, then if they clicked on my LIST FORM link they would be taken to a form that had their email address already filled in.

Can somebody, anybody please tell me step by step how the heck to do this. Or if there is an easier way to do it....

Thanks

Join the Best Internet Email Safelist at http://www.dspsafelist.com


Rivotti
User

Dec 19, 2000, 3:38 AM

Post #2 of 3 (657 views)
Re: Using cookies to auto fill HTML Form fields [In reply to] Can't Post

Hi, I'll try to make this simple:

First you have to create a form that sends the value os the field password
Now you create the cgi that get that info and then stores it in the cookie

################
# save_cookie.cgi #
################

#!/usr/bin/perl # Normally this is the path to perl
use CGI qw/:standart/; # for more info about the CGI module

$cookie_data = param('mail'); # Get the value in the fiel mail and gives his value to $mail

# Now save the data do the cookie
$final_cookie=new CGI->cookie(-name=>''mail, # the name of the cookie
-value=>$cookie_data, # the values you entered
-expires=>'+6M'); # ...
print new CGI->header(-cookie=>$final_cookie); # saves it...

Get here more info on setting cookies

Now to getthe cookie create another cgi file

###############
# get_cookie.cgi #
###############

#!/usr/bin/perl
use CGI qw/:standart/;

# Get the cookie data
$cookie_data=new CGI->cookie("mail");

# Now just use it
print "E-mail : $cookie_data\n";

this is a very simple way but will do for your needs...

Rivotti



Mortimer
journeyman

Dec 26, 2000, 6:52 AM

Post #3 of 3 (634 views)
Re: Using cookies to auto fill HTML Form fields [In reply to] Can't Post

Cookies can be disabled, deleted and regarded as somewhat uncivilised by many people. It
would be more reliable to do it from your user data file, which should be lurking around
somewhere on your server.
If you require the user to submit his email address when he registers, you can email
him his encrypted password and username, and store the form data in a file. Therefore you
should be able to retrieve, and drop any data from this file straight into another form
when he logs on, and also into a cookie which can be set to last for the duration of this
visit, or longer. This cookie is a lot more reliable, and can be used for things like
maintaining state and filling in forms.
Say you have `pass.dat' that stores user details thus:

as8dfkwr324JKd8&name=Jack&surname=Horner&Email+address=jack@corner.com&username=Plum

ie: the raw data from a registration form. In this case, the encrypted password is at the
front, and the username on the end. Using a parser that yields `%formData' you could verify
the username and password like this;

if($formData{'enterforum'}){ # If logon button was pressed.
$salt=substr($formData{'pw'},(length($formData{'pw'})-2),2);
$encLogonPass=crypt($formData{'pw'},$salt);
if(-e $pwFile && $formData{'pw'} ne '' && $formData{'username'} ne ''){
open(PASS,"<pass.dat")or die("Cannot open pass.dat for input. $!");
while(<PASS>){
if($_=~m/^($encLogonPass)/g){
$userDetails=$';
if($userDetails=~/$formData{'username'}$/){
$formFlag=1;
last;
}
}
}
close(PASS);
}
}

So if the username and password are okay, you could retrieve the data like this:

if($formFlag == 1){
my(@data)=split('&',$userDetails);
shift(@data);
foreach(@data){
s/\+/ /g;
my($name,$val)=split('=',$_);
$name=~s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
$val=~s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
$details{$name}=$val;
}
}

The user's details are now stored in Ūtails.

Dave. (Wannabe Perl hacker).
www.dmscripts.com - davemortimer@one.net.au


 
 


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

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