In a message dated 5/15/01 11:11:32 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:


> This is what I do (or at least, something vey similar to it):
> 
> proc fetch_form_variables {varName} {
>     upvar 1 $varName arrayName
>     set form [ns_getform]
>     set size [ns_set size $form]
>     for {set i 0} {$i < $size} {incr i} {
>         set [set arrayName]([ns_set key $form $i]) [ns_set value $form $i]
>     }
> }
> 


Two issues that I see with this code 

1) if i'm not mistaken, it will throw the error "can't read "arrayName": no 
such variable", because of [set arrayName] which is unneccessary.

2) if the form has values from a multiple select, array set -- if it was 
working -- would step on the duplicate keys each time, resulting in only the 
last value in the multiple list being set.

Rewritten, with multi-select support, it'd be:

proc fetch_form_variables {varName} {
� � upvar $varName arrayName
� � set form [ns_getform]
� � for {set i 0} {$i < [ns_set size $form]} {incr i} {
� � � � lappend arrayName([ns_set key $form $i]) [ns_set value $form $i]
� � }
}

The problem with this is that if any of the elements you've grabbed are 
SINGLE ITEMS but MULTIPLE WORDS, you'll have a list element: 
       
       {i was a form input}

instead of 

       i was a form input

...which can cause issues.

(Compare these two lines of code:

       lappend foo "hello bar"
       set foo "hello bar"

Very different result.)

To fix, you could then do something like 

       if {[llength $arrayName($key)] == 1} {
           set arrayName($key) [lindex $arrayName($key) 0]
       }


N.B. upvar defaults to 1, so no need, really, to include the "1".

-- miichael

___________________
 michael richman 
 aol local technology         
 214.954.6204

Reply via email to