" What's parsing your POST data? Neither CGI.pm nor CGI::Lite gives you a hash for a multiple select." Hmmmm.. I used CGI.pm to retrive the post variables. If it returns a list, it is a big problem for me because i need keys to keep options highlighted in the menu in case of any error, missing values... I posted my code below... Inside the check function I included php functions (i have no idea about their perl equivalents) named "is_array" and "empty" to indicate where i need to check the post variable... I am new to Perl, and I translated this code from a php class that i have created for my projects. So it might have a lot of flaws that i am not aware of... THanks a lot for the responses...
# this is the sub that creates the select menu sub elementSelect { my($self,$nm)=@_; # unique keys are data/sql, default # I use data key to create static select menus # sql key to create dynamic menus from tables my $data_array; my $row; my $multiple="no"; my $select=undef; if($self->{ELEMENTS}->{$nm}->{data}){ $data_array=$self->{ELEMENTS}->{$nm}->{data}; }elsif($self->{ELEMENTS}->{$nm}->{sql}){ my $sql=$db->prepare($self->{ELEMENTS}->{$nm}->{sql}); $sql=$db->execute(); while($row=$sql->fetchrow_arrayref){ $data_array->[$row->[0]]=$row->[1]; } } $multiple="yes" if defined $self->{ELEMENTS}->{$nm}->{attributes}->{ +multiple}; $select="<select name='".$nm; if($multiple eq "yes"){ $select.="[]"; } $select.="' ".$self->getAttributes($nm).">"; if($multiple eq "no"){ $select.="<option value=''>select ".$self->{ELEMENTS}->{$nm}->{def +ault}."</option>"; } if($multiple eq "yes"){ while(my($key,$value)=each(%{$data_array})){ my $selected; if(($self->{PVARS}->{$nm} && $self->{PVARS}->{$nm}->{$key}) || ( +!$self->{PVARS}->{$nm} && $self->{VARS}->{$nm}->{$key})){ $selected="selected"; }else{ $selected=""; } $select.="<option value='".$key."' ".$selected.">".$value."</opt +ion>"; } }else{ while(my($key,$value)=each(%{$data_array})){ my $selected; if(($self->{PVARS}->{$nm} && $key eq $self->{PVARS}->{$nm}) || + (!$self->{PVARS}->{$nm} && $key eq $self->{VARS}->{$nm})){ $selected="selected"; }else{ $selected=""; } $select.="<option value='".$key."' ".$selected.">".$value."</optio +n>"; } } $select.="</select>"; return $select; } ##################################################### # DATA VALIDATION FUNCTIONS # this is where i have the problem, the checkRequired sub # should be compatible with both single values and lists in # case of multiple selects ###################################################### sub checkRequired { my($self,$nm)=@_; my $o=""; if(is_array($self->{POST}->param($nm))){ # check for multiple select if(empty($self->{POST}->param($nm))){ # check the array has any values in it # maybe if(self->{POST}->param($nm))??? push @{$self->{ERRORS}},"Please enter ".$self->{ELEMENTS}->{$nm} +->{message}."!"; }else{ $o=$self->{POST}->param($nm); } }else{ # value is scalar if($self->{POST}->param($nm) eq ""){ push @{$self->{ERRORS}},"Please enter ".$self->{ELEMENTS}->{$nm} +->{message}."!"; }else{ $o=$self->{POST}->param($nm); } } return $o; }

In reply to Re^2: hashes by Anonymous Monk
in thread Detect and reset hashes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.