In article <3827643.1005996666@[10.0.0.140]>,
[EMAIL PROTECTED] (Birgit Kellner) wrote:
> 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
>
look in cgi_docs.html (comes with CGI.pm when you install it.. check in
the .cpan directory or wherever you installed it)
under Creating a New CGI Query Object, there's the sub-header "Fetching
the Parameter List as a Hash" which has the details you need.
--
Scott R. Godin | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services | web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]