Is this 2004? or 1994? I forgot.
On Fri, Jun 11, 2004 at 08:09:52PM +1000, William Kolln wrote:
> HI
>
> Any help will be greatly appreciated.
>
> The below statement is my parsing statement. It may be antiquated but it
> works.
>
> I want to process input from a select form that has two names and two name
> values
> name=group1 , value1=xxxx
> name=group2 , value2=yyyy
>
>
> IN the below statement, how do I process this information so that:
>
> a] if a user selects both group1 and group2 from the drop lists, then it
> will join them together and parse both groups as one.
>
> b] if a user selects either group1 or group2 the it parses either group.
>
> I have tried to use . for joining strings (concatenate)
>
>
>
> ################################
> # parse form input
NO! oh yeah, it is 2004. There's no reason to reinvent this wheel.
Especially considering that you're not likely to do it better than
entire community ;).
use CGI;
my $c = new CGI;
my @name = $c->param('name');
my @value = $c->param('value');
my %FORM = ();
@[EMAIL PROTECTED] = @value;
my @configs = qw(bgcolor link_color .. );
my %CONFIG = ();
foreach my $attr ($c->param) {
if(grep /^$attr$/, @configs) {
$CONFIG{$attr} = $c->param($attr);
}
elsif($attr eq 'name' || $attr eq 'value') {
# skip the name/value pairs
next;
}
else {
$FORM{$attr} = $c->param($attr);
}
}
Isn't that a little bit cleaner?
perldoc CGI
and remove this subroutine. If you ever see this subroutine again,
replace it. Never recreate it.
> sub parse_form {
> my(@pairs);
> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
> # Get the input
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> # Split the name-value pairs
> @pairs = split(/&/, $buffer);
> }
>
> foreach $pair (@pairs) {
> my($name, $value) = split(/=/, $pair);
>
> $name =~ tr/+/ /;
> $name =~ s/%([\a-fA-F0-9][\a-fA-F0-9])/pack("C", hex($1))/eg;
>
> $value =~ tr/+/ /;
> $value =~ s/%([\a-fA-F0-9][\a-fA-F0-9])/pack("C", hex($1))/eg;
>
> $value =~ s/<!--(.|\n)*-->//g;
>
> if ($name eq 'bgcolor' || $name eq 'background' || $name eq
> 'link_color' ||
> $name eq 'vlink_color' || $name eq 'text_color' || $name eq
> 'alink_color' ||
> $name eq 'title' || $name eq 'sort' || $name eq 'print_config'
> ||
> $name eq 'return_link_title' || $name eq 'return_link_url' &&
> ($value)) {
> $CONFIG{$name} = $value;
> }
> elsif ($name eq 'required') {
> @required = split(/,/,$value);
> }
> elsif ($name eq 'exclude') {
> @exclude = split(/,/,$value);
> }
> else {
> if ($FORM{$name} && ($value)) {
> $FORM{$name} = "$FORM{$name}, $value";
> }
> elsif ($value) {
> $FORM{$name} = $value;
> }
> }
> }
> }
> #######################################
>
>
> William L Kolln
> Email: [EMAIL PROTECTED]
>
> ##############################
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
--
Brad Lhotsky <[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>