Skip to content

Instantly share code, notes, and snippets.

@Aqua-Ye
Created April 2, 2012 10:53
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 Aqua-Ye/2282558 to your computer and use it in GitHub Desktop.
Save Aqua-Ye/2282558 to your computer and use it in GitHub Desktop.
HttpRequest.get_form_data for Opa
function get_form_data() {
function decode(s) { String.replace("+", " ", Uri.decode_string(s)) }
match (HttpRequest.get_body()) {
case {none}: StringMap.empty
case {some:body}:
match (Parser.try_parse(UriParser.query_parser, body)) {
case {none}: StringMap.empty
case {some:list}:
List.fold(function((a, b), acc) {
StringMap.add(decode(a), decode(b), acc)
}, list, StringMap.empty)
}
}
}
@Aqua-Ye
Copy link
Author

Aqua-Ye commented Apr 2, 2012

An example of usage :

function start() {
  data_map = get_form_data()
  jlog("{data_map}")
  <form name="myForm" method="post" action="/">
    <input type="text" name="hello"/>
    <input type="file" name="file"/>
    <textarea name="world"/>
    <input type="submit"/>
  </form>
}

Server.start(Server.http, { title:"Form POST", page:start })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment