I've discovered a "problem" in DekiScript (confirmed by Mindtouch support) where, when processing passed arguments from a form, multiple arguments with the same name will not be correctly processed: instead, only the last argument with the same name will be kept and added to the __request.args map.
E.g. I create a form with six checkboxes on it, all named "province" and then assign each a different value (BC, AB, ON, QC, ..., YT). When a user submits the form my expectation is that an array is created for "province" containing the selected checkboxes. This is the behaviour in PHP. In DekiScript, __request.args contains a "province" argument, however, it only contains the "last" value that was selected (so, if the user selected "YT" + anything else, "YT" would always be the only value for "province"--assuming it was the last entry in the "province" list of checkboxes).
The work-around suggested by Mindtouch Support is to name each checkbox uniquely.
An alternative is to use the following code in your DekiScript: it correctly sets up an arguments variable (in this case "the_args"), where arguments with multiple passed values are created as lists. I haven't tested it extensively, but it seems to work ok. The catch, is that it makes use of the __request.referer variable, which isn't always set (e.g. I'm not sure if it's set if you submit the form multiple times...). So, be sure to test with your application and ensure it works for you before relying on it.
Code:var temp_referer = __request.referer; var passed_args = string.split( string.remove( temp_referer, 0, string.indexof( temp_referer, "?" ) + 1 ), "&" ); var the_args = {}; foreach( var entry in passed_args ) { var temp = string.split( entry, "=" ); // check if the key already exists, and if so, turn it into an array if( Map.Contains( the_args, temp[0] ) ) { // retrieve the existing values, check if already an array if( typeof the_args[temp[0]] == "str" ) { var temp_array = [ the_args[temp[0]], temp[1] ]; } else { var temp_array = the_args[temp[0]]; let temp_array ..= [ temp[1] ]; } // store the array let the_args ..= { (temp[0]) : temp_array }; } else { let the_args ..= { (temp[0]) : temp[1] }; } }
BTW, here's the official explanation as to why this is happening:
"The desired behavior is not possible inside DekiScript. In a traditional PHP-based system, the checkboxes could all have the same name: name="province[]" , for example. Then, while processing a POST request, PHP turns the selected boxes into an array (thanks to the '[]' notation).
DekiScript can not process POST data, so this technique is not available. DekiScript can only process GET data. When submitted by a form, the GET data is passed as part of the query string. The resulting query string for the GET request will contain provice=BC&province=AB (for example) when the form is submitted. While this is a valid query string, the actual processing of it is not defined when duplicate keys are supplied.
We have confirmed that DekiScript processes duplicate keys in the exact way we are seeing: It overwrites the values until the last one is encountered. Therefore, the left-most 'province' value is what is seen.
In summary, the DekiScript processor is handling the GET request without error. Our recommendation is that you name each checkbox uniquely so that there are no duplicate keys in the query string. This will provide all of the selected values when __request.args is inspected."


Reply With Quote