[xwiki-users] Handling arrays in forms
In PHP it is acceptable for forms to have arrays. For example, from http://php.net/manual/en/faq.html.php#faq.html.arrays the following form could be submitted: <form action="" method="post"> <input name="MyArray[]" value=1 /> <input name="MyArray[]" value=2 /> <input name="MyArray[]" value=3 /> <input name="MyArray[]" value=4 /> <input type="Submit" /> </form> And in PHP the submitted inputs would be available as an array at $_POST['MyArray'] Out of curiosity, does XWiki have any similar support for form arrays? I tried a simple example, for which the returned result was a single value ("1"). Does this mean XWiki ignores multiple request parameters of the same name, or is there another way? {{groovy}} def values = request.get('MyArray[]') println "${values.getClass()}" println "${values}" {{/groovy}} {{html}} <form action="" method="post"> <input name="MyArray[]" value=1 /> <input name="MyArray[]" value=2 /> <input name="MyArray[]" value=3 /> <input name="MyArray[]" value=4 /> <input type="Submit" /> </form> {{/html}}
Looks like arrays are handled properly, but need to be accessed more carefully. getParameterValues <http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org/xwiki/platform/xwiki-platform-oldcore/6.3/xwiki-platform-oldcore-6.3-javadoc.jar/!/com/xpn/xwiki/web/XWikiServletRequest.html#getParameterValues(java.lang.String)> can return an array of strings, as demonstrated here: {{groovy}} println "= Parameter Names =" request.getParameterNames().each{ println "* Item: $it" } println "= Parameter Values =" request.getParameterValues('MyArray[]') .each{ println "* Item: $it" } {{/groovy}} {{html}} <form action="" method="post"> <input name="MyArray[]" value=6 /> <input name="MyArray[]" value=7 /> <input name="MyArray[]" value=8 /> <input name="MyArray[]" value=9 /> <input type="Submit" /> </form> {{/html}} -- View this message in context: http://xwiki.475771.n2.nabble.com/Handling-arrays-in-forms-tp7593719p7593723... Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (2)
-
beldaz -
Bryn Jeffries