Well here is an old example by Lincoln Stein(CGI.pm author). I'm sure it's somewhere on the net, but I couldn't find a link so I'll post it here. The all you need to add is encryption of the cookie( if needed).

Also check out CGI docs and search for cookies.

#!/usr/bin/perl use CGI qw(:standard); @ANIMALS=sort qw/lion tiger bear pig porcupine ferret zebra gnu ostric +h emu moa goat weasel yak chicken sheep hyena dodo lounge-lizard squirrel rat mouse hedgehog racoon baboon kangaroo hippopotamus giraffe/; # Recover the previous animals from the magic cookie. # The cookie has been formatted as an associative array # mapping animal name to the number of animals. %zoo = cookie('animals'); # Recover the new animal(s) from the parameter 'new_animal' @new = param('new_animals'); # If the action is 'add', then add new animals to the zoo. Otherwise # delete them. foreach (@new) { if (param('action') eq 'Add') { $zoo{$_}++; } elsif (param('action') eq 'Delete') { $zoo{$_}-- if $zoo{$_}; delete $zoo{$_} unless $zoo{$_}; } } # Add new animals to old, and put them in a cookie $the_cookie = cookie(-name=>'animals', -value=>\%zoo, -expires=>'+1h'); # Print the header, incorporating the cookie and the expiration date.. +. print header(-cookie=>$the_cookie); # Now we're ready to create our HTML page. print start_html('Animal crackers'); print <<EOF; <h1>Animal Crackers</h1> Choose the animals you want to add to the zoo, and click "add". Come back to this page any time within the next hour and the list of animals in the zoo will be resurrected. You can even quit Netscape completely! <p> Try adding the same animal several times to the list. Does this remind you vaguely of a shopping cart? <p> <em>This script only works with Netscape browsers</em> <p> <center> <table border> <tr><th>Add/Delete<th>Current Contents EOF ; print "<tr><td>",start_form; print scrolling_list(-name=>'new_animals', -values=>[@ANIMALS], -multiple=>1, -override=>1, -size=>10),"<br>"; print submit(-name=>'action',-value=>'Delete'), submit(-name=>'action',-value=>'Add'); print end_form; print "<td>"; if (%zoo) { # make a table print "<ul>\n"; foreach (sort keys %zoo) { print "<li>$zoo{$_} $_\n"; } print "</ul>\n"; } else { print "<strong>The zoo is empty.</strong>\n"; } print "</table></center>"; print <<EOF; <hr> <ADDRESS>Lincoln D. Stein</ADDRESS><BR> <A HREF="./">More Examples</A> EOF ; print end_html;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: How to preload user data on form via cookie & Perl/CGI? by zentara
in thread How to preload user data on form via cookie & Perl/CGI? by JCHallgren

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.