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]
    }
}

This proc takes the name of an array into which the key=value pairs
submitted should be set.  I don't do (and probably should) any error
checking to ensure that the name being passed is an array that already
exists (and perhaps we should throw an error and not clobber it).

Call it within code like:

  fetch_form_variables form

and access form variables like this:

  ns_puts "Hello, $form(username)!"


This brings me to ask the question:  why isn't there an [ns_set array]
which returns the ns_set as an array that can be passed to
[array set]?  Or, am I missing something?

- Dossy


On 2001.05.15, Eduards Cauna <[EMAIL PROTECTED]> wrote:
> What is the best way to access form variables (i.e., variables submitted
> using html form) in adp pages?
> There is code I am using now but not sure I am understand everything what
> there happens.
>
>
> proc fetch_variables { } {         # fetch all variables from forms and
> fancy urls
>         uplevel {
>         set form [ns_getform]
>         set form_size [ns_set size $form]
>         set form_counter_i 0
>         while {$form_counter_i<$form_size} {
>             set [ns_set key $form $form_counter_i] [ns_set value $form
> $form_counter_i]
>             incr form_counter_i
>         }
>      }
> }

--
Dossy Shiobara                       mail: [EMAIL PROTECTED]
Panoptic Computer Network             web: http://www.panoptic.com/

Reply via email to