--On Dienstag, 31. Juli 2001 08:13 -0400 "Jeff 'japhy/Marillion' Pinyan"
<[EMAIL PROTECTED]> wrote:
> On Jul 30, Randal L. Schwartz said:
>
>> Stop right there. This is not a valid form. There's no guarantee to
>> the return ordering of form fields. You're lucky if it has worked so
>> far, but I wouldn't even begin to bet an e-commerce site on it.
>>
>> Just generate unique form fields, and all will be well.
>
> From CGI.pm:
>
> NOTE: As of version 1.5, the array of parameter names
> returned will be in the same order as they were submitted by
> the browser. Usually this order is the same as the order in
> which the parameters are defined in the form (however, this
> isn't part of the spec, and so isn't guaranteed).
>
> Perhaps it should be part of the spec. It seems like browsers do it all
> the time.
Thanks for the information. If it is indeed necessary to have unique
fields, I reckon I could just use the database key as a name of the input
field for the number of copies:
<input type=text size=3 maxlength=3 name="$db_key">
$db_key will be numerical, so i'll get a query string like this:
"thisorder=1&15=27&34=0&45=&2=678&db=default"
I can then extract of all key/value-pairs with numerical keys to a hash in
order to get all values of $db_key, i.e. all entered numbers of copies:
use CGI qw(:standard);
$query = new CGI;
@names = $query->param;
my %copies;
foreach $name (@names) {
if (param($name)) { # exclude cases where the user has not entered a
number of copies
if (($name =~ /^\d+/) && (param($name) =~ /^[1-9]/)) {
$copies{'$name'} = param($name);
}
}
The regexps in the second if-condition should specify that (a) the name in
the query-string is numerical, and that (b) it has a numeric value (we
exclude cases where silly users write words into the copies-field) other
than 0 (i.e. one that does not start with zero).
For all I can tell, this works. Any ideas for further simplification?
Birgit Kellner
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]