Parsing multiple values from HTML forms? 
Author Message
 Parsing multiple values from HTML forms?

I come up against this frequently.  I have a form that has a multiple
<select> tag.  

Is there any way to parse multiple values being assigned to the input
variable on the CGI/PERL side?  I assume there is no way, unless I
resort to CGI.pm libary -- which means entirely rewriting all my Perl4
scripts... :-(

Chuck Wyatt



Mon, 24 May 1999 03:00:00 GMT  
 Parsing multiple values from HTML forms?

Quote:

> I come up against this frequently.  I have a form that has a multiple
> <select> tag.

> Is there any way to parse multiple values being assigned to the input
> variable on the CGI/PERL side?  I assume there is no way, unless I
> resort to CGI.pm libary -- which means entirely rewriting all my Perl4
> scripts... :-(

> Chuck Wyatt

Chuck

Upgrade - believe me it's worth it.  The docs. that come with CGI.pm
also have guidance on moving from cgi-lib...."resort to CGI.pm" almost
sounds like it's a retrograde step !  Nothing could be further from the
truth.

David
http://skpc10.rdg.ac.uk



Mon, 24 May 1999 03:00:00 GMT  
 Parsing multiple values from HTML forms?

Quote:

>I come up against this frequently.  I have a form that has a multiple
><select> tag.  

>Is there any way to parse multiple values being assigned to the input
>variable on the CGI/PERL side?  I assume there is no way, unless I
>resort to CGI.pm libary -- which means entirely rewriting all my Perl4
>scripts... :-(

>Chuck Wyatt

Here is the script I use for t{*filter*} FORM content.
Just require it and then trimmer($buffer) returns %VALUES. I use this a lot
because I don't need everything that CGI.pm does.

#!/usr/bin/perl
sub trimmer {



                my($key,$value) = split(/=/,$pair);
                $value =~ tr/+/ /;
                $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                $value =~ s/\n/ /;
                $value =~ s/\cM//;
                if ($VALUES{$key}) {

                        # Here we save the multiple selects as one value
                        # Joined with ;; or whatever you want.
                        $VALUES{$key} = join(';;',$VALUES{$key},$value);

                } else {
                        $VALUES{$key} = $value;
                }
        }

Quote:
}

1;

--

                                                Bryan C. Andregg
                                        Systems/Network Administrator
                                        Internet Direct Communications
                                                (913) 841.2220
----------------------------------------------------------------------
Linux, the FAT free operating system.



Mon, 24 May 1999 03:00:00 GMT  
 Parsing multiple values from HTML forms?

Quote:

> Upgrade - believe me it's worth it.  The docs. that come with CGI.pm
> also have guidance on moving from cgi-lib...."resort to CGI.pm" almost
> sounds like it's a retrograde step !  Nothing could be further from the
> truth.

It's a matter of taste really, both lib's are kept up to date, you get a
lot of new features with CGI.pm, but if you don't want those, well then
stick with cgi-lib.

To get back to Chucks question, cgi-lib also handels multible values
from select. The values are seperated by \0. So you just split on the
\0's.

I hope this helps
Borup



Tue, 25 May 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Parse::ecDescent and multiple values

2. Web Form: Fields with Multiple values

3. Multiple Form Values && SQL

4. Printing multiple HTML pages of Tables and Forms

5. Advise <select multiple> for html forms

6. Perl w/ multiple select list in html forms?

7. parsing html forms into cgi.pm perl

8. parsing html and forming xml

9. parsing contents of html form w/net::smtp

10. help needed with parsing a HTML form

11. HTML Form Parsing using perl5

12. Parsing html tag attributes & values in Perl

 

 
Powered by phpBB® Forum Software