I think we need function for getting HTTP forms arrays. As example,
this is a set of records from rich internet applications.
Results of popular js function serializeArray() from jQuery or analogs
can't be readed simple in AOL now. The function
ns_querygetall is very usefull, but this is not enough!


See code here:
http://pastebin.com/FsvA7ZDs
or below:


# jQuery example
# $.post("/json/answer/set/question/",$("#form_answers").serializeArray())
proc ns_querygetarray {} {
    # name {name1 name2 ...} id {id1 id2 ...} ...
    set info [dict create]
    set form [ns_getform]
    set size [ns_set size $form]
    # empty form
    if { $size == 0 } return
    for {set i 0} {$i < $size} {incr i} {
        set k [ns_set key $form $i]
        set v [ns_set value $form $i]
        # empty-named element is not exists
        if { $k eq "" } continue
        # check for valid names
        if { [regexp -- {^\w+$} $k] == 0 } {
            error "Field name is dangerous (\"$k\")"
        }
        dict lappend info [string tolower $k] [string trim $v]
    }
    # empty form (as form with only empty elements)
    if { [llength $info] == 0 } return
    # all fields must have equal elements count
    set counter ""
    dict for {k v} $info {
        lappend counter [llength $v]
    }
    set counter [lsort -unique $counter]
    if { [llength $counter] > 1 } {
        error "Form arrays have non-equal length"
    }
    # transpose
    set infoT ""
    for {set i 0} {$i<$counter} {incr i} {
        set row ""
        foreach k [dict keys $info] {
            lappend row $k [lindex [dict get $info $k] $i]
        }
        lappend infoT $row
    }
    # {name name1 id id1 ...} {name name2 id id2 ...} ....
    return $infoT
}


-- 
Best regards, Alexey Pechnikov.
http://pechnikov.tel/


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to 
<lists...@listserv.aol.com> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to