> 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.

The code you're using now has the bad effect of letting the client
pollute your Tcl namespace. Consider what will happen if I send you a
URL like "/foo/bar.tcl?::env(PATH)=/tmp".  You are much better off
putting the form variables into a Tcl array.

In my own code, I do it like this:

    array set q {
        someVariable defaultForSomeVariable
        anotherVar anotherDefaultValue
    }

    getform q

And getform is defined like this:

    proc getform {arrayName} {
        upvar $arrayName a

        array set a {}

        set form [ns_getform]
        if {[string length $form] == 0} return
        for {set i 0; set n [ns_set size $form]} {$i < $n} {incr i} {
            set key [ns_set key $form $i]
            set value [ns_set value $form $i]
            if {![info exists state($key)]} {
                set state($key) 1
                set a($key) $value
            } elseif {$state($key) == 1} {
                set a($key) [list $a($key) $value]
                set state($key) 2
            } else {
                lappend a($key) $value
            }
        }
    }

My definition of getform is a bit more complex than some others.  If the
form variable name "x" appears twice in the HTTP request, my getform
will set q(x) to a proper two-element Tcl list.  This is useful if you
have two INPUT TYPE=TEXT boxes with the same name.

Reply via email to