[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mason
Subject:    Re: [Mason] Quantity textboxes
From:       "P. Fleury" <fleury () users ! sourceforge ! net>
Date:       2004-04-17 13:44:45
Message-ID: 408134CD.9040305 () users ! sourceforge ! net
[Download RAW message or body]

Hi Alex,

The list may be out of order (because the parameter submit order is 
unspecified) and you may end-up with a hash which does not have the 
intended values...

My approach to this is to have a fields containing the item numbers, as 
a list (or several hidden fields, so that Mason puts them into an array).
Then, for each iktem number, I can put any number of field, having the 
item number as suffix, getting fields like giftwrap007, qty007, 
delete007, and even some hidden fields related to the article, like 
artid007.

I'll have something like
<input type=hidden name='items' value='007 012 768'>
<input type=checkbox name='giftwrap007' checked>
...
When the parameters get in, I read the list of items,  iterate through 
them and decode them to a hash:
<%args>
    $items
</%args>
% my %items;
% foreach ( split /\s+/o, $items ) { $items{$_} = decode_item(\%ARGS, $_) }

where 

# This can be in <%once>, a classic Perl module, or in the handler.pl, 
or even in the httpd.conf :-)
sub decode_item {
    my ($a,$id) = @_;
    my %vals = map { (/(.*)${id}$/)[0] => $a->{$_} } # Map them to   
'giftwrap' => $a->{giftwrap007}
                                                     # The first 
expression removes the id from the key
                      grep { /${id}$/ }              # Select only the 
ones which end in $id
                      keys %$a;                      # Consider all 
transmitted arguments
    return \%vals;
}


The nice thing here is that for checkboxes (and I think radioboxes too 
though I have none on my site), you get the value 'on' as a return, or 
otherwise, the hash value is not defined. Therefore, you can do things like

% if ( $item{"007"}->{giftwrap} ) {
    You have selected giftwrap for this item.
% }


I have also used this for setting up fields which needs multi-values as 
a form, but can be represented as a single item in Perl, like setting a 
date. the decode sub will find whatever ends in *day, *month, etc. (from 
<select> form fields) and return me a DateTime.

Hope this helps :-)
--pascal

Alexander Karelas wrote:

> For the quantity textboxes, I thought of the following solution:
> Let all textboxes be named "quantity" and let each be proceeded by a 
> hidden field also named with the word "quantity" and value equal to 
> the product's id. Then place in the <%args> section of the receiving 
> script, a hash called %quantity. Then the script will have a hash, 
> with keys equal to the product id's that the customer is buying, and 
> the quantities themselves as the values of those keys.
>
> It's the "deletion" checkboxes that are troubling me.
>
> Thanks,
> - Alex
>
> Alexander Karelas wrote:
>
>> How does one go around processing data with mason from the following 
>> form situations?
>>
>> [...]
>
>
>


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic