Carol:
I believe that I have a potential solution to the problem you have been kind enough to join me in wrestling with for the past week.
First, I have concluded that my original hunch was correct and that we cannot assign a JavaScript array element to a Perl scalar. I have concluded this from the fact that what we have developed so far works EXCEPT for the assignments in question, i.e., the following works:
&switch_to_neworders;
$in{'UserID'} = $db_userid;
$in{'Date'} = &get_date;
$in{'Field1'} = $BookletsArray[$i];
$in{'Field2'} = $BookletsArray[$i+1];
open (ID, "<$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) { flock(ID, 1); }
$in{$db_key} = <ID> + 1;
close ID;
open (DB, ">>$db_file_name");
print DB &join_encode(%in);
close DB;
open (ID, ">$db_id_file_name");
print ID $in{$db_key};
close ID;
except for the assignments
$in{'Field1'} = $BookletsArray[$i];
$in{'Field2'} = $BookletsArray[$i+1];
These are left blank in the database while ID, UserID and Date make it in okay.
============
So, I did some searching and I found an HTTP Cookie Library written in Perl from a gentleman by the name of Matt Wright (Matt's Script Archive, http://www.worldwidemart.com/scripts/).
Using this script is quite straightforward:
1) Include it as a required library in the .cfg file as
require $db_script_path . "/cookie.lib";
Matt has several routines for manipulating cookies in his script. The only one we are concerned with is the one which reads cookies:
sub GetCookies {
...
}
2) Recall that the cookies store the user's requests obtained via forms on the client side. To retrieve the information contained in the cookie "Booklets" I call the routine in my userProfile_html.pl script as:
if (&GetCookies('Booklets')) {
...
}
The return value of &GetCookies is 1 if the cookie exists, 0 otherwise. Straightforward enough. I tested the routine. From my form pages the Booklets cookie was created and saved with the information
S1|1
In this case, "S1" is the name of the item and the quantity is "1", with "|" as the delimiter.
Doing a simple Perl "print"
if (&GetCookies('Booklets')) {
print "The Booklets cookie = $Cookies{'Booklets'}"
}
the printed return is
The Booklets cookie = S1%7C1
which is recognized as the URLencoded equivalent of S1|1.
============
Now we have a routine to read the cookie values in native Perl, none of this JavaScript <=> Perl stuff. The question now becomes one of "now that we can read the HTTP cookie in Perl, what is the best way to get it into the database?"
My thoughts at this point are to convert the hash to an array much like what I was doing in JavaScript so that we may still loop through the array for a multiple item order. Your thoughts? There must be a standard library routine out there to take a delimited hash like this and stuff it into an array, I would think. In JavaScript it is very easy:
var Booklets = new Cookie("Booklets")
var BookletsData = Booklets.get()
if (BookletsData != "") {
var BookletsArray = BookletsData.split("|")
Suggestions? Perls of wisdom? ;-)
This may be a good case for your future reference. I am sure I am not the only one interested in getting information from the user via forms, storing the information in a cookie, and having dbman take this cookie info to stuff into a database (I hope so anyway, you have helped a lot! and I tip my hat to you).
Jim
P.S. By the way, I thought the same thing about the while loop, but I figured it was just another one of those wierd Perl things since this is the way it is outlined to be used in the "Perl Programmer's Reference Guide". No other language I know of, including C, C++, Pascal, Modula 2, Ada, Fortran, Basic and JavaScript that I have worked with use the while loop quite like this.
I believe that I have a potential solution to the problem you have been kind enough to join me in wrestling with for the past week.
First, I have concluded that my original hunch was correct and that we cannot assign a JavaScript array element to a Perl scalar. I have concluded this from the fact that what we have developed so far works EXCEPT for the assignments in question, i.e., the following works:
&switch_to_neworders;
$in{'UserID'} = $db_userid;
$in{'Date'} = &get_date;
$in{'Field1'} = $BookletsArray[$i];
$in{'Field2'} = $BookletsArray[$i+1];
open (ID, "<$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) { flock(ID, 1); }
$in{$db_key} = <ID> + 1;
close ID;
open (DB, ">>$db_file_name");
print DB &join_encode(%in);
close DB;
open (ID, ">$db_id_file_name");
print ID $in{$db_key};
close ID;
except for the assignments
$in{'Field1'} = $BookletsArray[$i];
$in{'Field2'} = $BookletsArray[$i+1];
These are left blank in the database while ID, UserID and Date make it in okay.
============
So, I did some searching and I found an HTTP Cookie Library written in Perl from a gentleman by the name of Matt Wright (Matt's Script Archive, http://www.worldwidemart.com/scripts/).
Using this script is quite straightforward:
1) Include it as a required library in the .cfg file as
require $db_script_path . "/cookie.lib";
Matt has several routines for manipulating cookies in his script. The only one we are concerned with is the one which reads cookies:
sub GetCookies {
...
}
2) Recall that the cookies store the user's requests obtained via forms on the client side. To retrieve the information contained in the cookie "Booklets" I call the routine in my userProfile_html.pl script as:
if (&GetCookies('Booklets')) {
...
}
The return value of &GetCookies is 1 if the cookie exists, 0 otherwise. Straightforward enough. I tested the routine. From my form pages the Booklets cookie was created and saved with the information
S1|1
In this case, "S1" is the name of the item and the quantity is "1", with "|" as the delimiter.
Doing a simple Perl "print"
if (&GetCookies('Booklets')) {
print "The Booklets cookie = $Cookies{'Booklets'}"
}
the printed return is
The Booklets cookie = S1%7C1
which is recognized as the URLencoded equivalent of S1|1.
============
Now we have a routine to read the cookie values in native Perl, none of this JavaScript <=> Perl stuff. The question now becomes one of "now that we can read the HTTP cookie in Perl, what is the best way to get it into the database?"
My thoughts at this point are to convert the hash to an array much like what I was doing in JavaScript so that we may still loop through the array for a multiple item order. Your thoughts? There must be a standard library routine out there to take a delimited hash like this and stuff it into an array, I would think. In JavaScript it is very easy:
var Booklets = new Cookie("Booklets")
var BookletsData = Booklets.get()
if (BookletsData != "") {
var BookletsArray = BookletsData.split("|")
Suggestions? Perls of wisdom? ;-)
This may be a good case for your future reference. I am sure I am not the only one interested in getting information from the user via forms, storing the information in a cookie, and having dbman take this cookie info to stuff into a database (I hope so anyway, you have helped a lot! and I tip my hat to you).
Jim
P.S. By the way, I thought the same thing about the while loop, but I figured it was just another one of those wierd Perl things since this is the way it is outlined to be used in the "Perl Programmer's Reference Guide". No other language I know of, including C, C++, Pascal, Modula 2, Ada, Fortran, Basic and JavaScript that I have worked with use the while loop quite like this.