Working with parameters with the same name
(1) By silas (silasdb) on 2024-01-09 00:50:11 [source]
ere!
First of all, thanks for this incredible framework! :-)
I'm building a small web application using wapp. I have some input fields that return results as multiple parameters with the same name. Example:
<select name="bicycles" multiple>
<option value="specialized">Specialized</option>
<option value="scott">Scott</option>
<option value="gt">gt</option>
...
</select>
User can select multiple choices. If the user select the first two choices, generated query is:
bicycles=specialized&bicycles=scott
As you know, this is the standard way to return lists of things to the server and web languages and framework usually accept this and show the result as an array or vector.
wapp currently considers only the last parameter and the others are lost. This is done in line 589 of wapp.tcl
:
dict set wapp $nm [wappInt-decode-url [lindex $qsplit 1]]
I tried replacing dict set
for dict lappend
, but then single strings started to show surrounded by braces. So, I replaced that line with the following code:
set p [wappInt-decode-url [lindex $qsplit 1]]
if {[dict exists $wapp $nm]} {
dict lappend wapp $nm $p
} else {
dict set wapp $nm $p
}
... and it seems to solve the problem (returning to the caller of [wapp-param]
as a list, but I didn't test deeply, so I don't know if there is any other side-effect. Of course, is up to the developer to know how to handle the response (as a string or a list).
What do you think of this? Any chance this change could be tested and maybe accepted? (Or maybe I'm just doing everything wrong?)
Thank you very much!
(2) By Stephan Beal (stephan) on 2024-11-20 12:08:24 in reply to 1 [link] [source]
I have some input fields that return results as multiple parameters with the same name.
FYI, Richard checked in an experimental change to support this:
/timeline?r=duplicate-parameters
It's not yet in the trunk, and is unlikely to reach there until/unless someone tries it out and confirms that it does the job without breaking anything.