Skip to content

Instantly share code, notes, and snippets.

@apb2006
Last active December 6, 2016 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apb2006/5f53b138449ee93798e35ddd364bdace to your computer and use it in GitHub Desktop.
Save apb2006/5f53b138449ee93798e35ddd364bdace to your computer and use it in GitHub Desktop.
BaseX RESTXQ reading repeated form values
(:~
: JSON form test apb 6dec 2016
:)
module namespace page = 'form-test';
import module namespace request = "http://exquery.org/ns/request";
declare
%rest:path("/form2")
%rest:GET
%output:method("html")
function page:form-get(){
<form action="/form2" method="POST" >
<input type="submit"/>
{for $i in 1 to 20
return <div> <h1>Instance {$i}</h1>
<label>f1: <input type="text" name="data1" /></label>
<label>f2: <input type="text" name="data2" /></label>
<select name="opt">
<option value="xforms">xforms</option>
<option value="xquery">xquery</option>
<option value="xslt">xslt</option>
</select>
</div>
}
</form>
};
declare
%rest:path("/form2")
%rest:POST
%output:method("html")
function page:form-post(){
let $names:=request:parameter-names()
let $size:=count(request:parameter($names[1])) (:number of instances from 1st param, assume all same:)
let $data:=for $i in 1 to $size
return map:merge($names!map:entry(.,request:parameter(.)[$i]))
for $instance at $i in $data
return <div>
<h1>$data[{$i}]</h1>
{serialize($instance,map{"method":"basex"}) (: show map for illustration :) }
</div>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment