I want to use CGI.pm to parse form input and store all name/value-pairs in 
a hash.

At present, the code I have reads like this:

my $in = new CGI;
my %in = &parse_form;

sub parse_form {

my @names = $in->param;
foreach my $name ( @names ) {
        if (param($name)) {
        $in{$name} = $in->param($name);}
        }
foreach my $key (keys %in) {
        if ($in{$key} eq "---") { # if this is a select field with no value 
selected, it will have the value "---"
                delete ($in{$key});
                }
        }
return (%in)}

There are two cases where I run into problems with this code:

- multiple select fields. I guess storing all names in @names gets rid of 
duplicate instances of names; at any rate, there are only unique array 
elements in @names when the foreach loop loops over them. The problem is 
that I won't know the names of the multiple select fields in advance, so I 
can't do something specific with them. I thought of adding a hidden input 
field to the form, with the name "multiple" and the value of the multiple 
select field. Then I could first parse this field and, if it has a value, 
treat the multiple select field differently from the other fields. (Implies 
that I can only have one multiple select field per form, but that's fine.)

- there are forms where I have a text input field named "fieldname" and a 
select field with the same name. Users are to select an item from the list 
or alternatively, if the item does not occur in the list, enter a new 
value. What the parse_form *should* do is ignore names without values from 
the start, and not read them into @names and *then* check whether they have 
values.

Thanks a lot for any advice,

Birgit Kellner


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to