Created
April 28, 2014 18:55
-
-
Save yetanotherion/11380863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {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