Skip to content

Instantly share code, notes, and snippets.

@yetanotherion
Created April 28, 2014 18:55
Show Gist options
  • Select an option

  • Save yetanotherion/11380863 to your computer and use it in GitHub Desktop.

Select an option

Save yetanotherion/11380863 to your computer and use it in GitHub Desktop.
{shared{
type insert_params = (string * string) deriving (Json)
}}
let insert_url_service_json =
Eliom_registration.Html5.register_service
~path:["posttest"]
~get_params:(ocaml "param" Json.t<insert_params>)
(fun (url, location) () ->
insert url location >>= fun () ->
Lwt.return (html
(head (title (pcdata ("Url inserted"))) [])
(body [pcdata (Printf.sprintf "Url %s correctly inserted in location %s" url location)])))
let insert_url_service =
Eliom_registration.Html5.register_service
~path:["posttest"]
~get_params:(string "url" ** string "location")
(fun (url, location) () ->
insert url location >>= fun () ->
Lwt.return (html
(head (title (pcdata ("Url inserted"))) [])
(body [pcdata (Printf.sprintf "Url %s correctly inserted" url)])))
let create_form =
(fun (url_name, location_name) ->
[p [string_input ~input_type:`Text ~name:url_name ();
string_input ~input_type:`Text ~name:location_name ();
string_input ~input_type:`Submit ~value:"insert" ();
]
])
let _ =
Eliom_registration.Html5.register_service ["inserttest"] unit
(fun () () ->
let f = get_form ~service:insert_url_service
~a:[a_onsubmit {{
ignore (Eliom_client.change_page ~service:%insert_url_service_json ("myurl", "mylocation") ())
}}] create_form
in
Lwt.return (html
(head (title (pcdata "Insert an url")) [])
(body [f])));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment