i have simple code
open Eliom_content.Html.D
open Eliom_service
open Eliom_parameter
module App = Eliom_registration.App (struct
let application_name = "eliom_playground"
let global_data_path = None
end)
let page_skeleton content =
Lwt.return @@ html (head (title (txt "")) []) (body [content])
let users_list = create ~path:(Path ["users"; "list"]) ~meth:(Get unit) ()
let user_form = create ~path:(Path ["users"; "new"]) ~meth:(Get unit) ()
let submit_user_form =
create
~path:(Path ["users"; "new"])
~meth:(Post (unit, string "name" ** string "fname" ** string "lname"))
()
type user = {name : string; fname : string; lname : string}
let users : user list ref = ref []
let () =
App.register ~service:users_list (fun () () ->
let rows =
List.map
(fun u -> tr [td [txt u.name]; td [txt u.fname]; td [txt u.lname]])
!users
in
div [a ~service:user_form [txt "add user"] (); table rows] |> page_skeleton);
App.register ~service:user_form (fun () () ->
let fields name fname lname =
[ Form.input ~input_type:`Text Form.string ~name
; Form.input ~input_type:`Text Form.string ~name:fname
; Form.input ~input_type:`Text Form.string ~name:lname
; Form.input ~input_type:`Submit Form.string ]
in
Form.post_form ~service:submit_user_form
(fun (name, (fname, lname)) -> fields name fname lname)
()
|> page_skeleton);
App.register ~service:submit_user_form (fun () (name, (fname, lname)) ->
users := {name; fname; lname} :: !users;
h1 [txt "user created"] |> page_skeleton)
After going to the form via a link from the list of users and sending the data, I get an error in the console: “[eliom:request] can’t silently redirect a Post request to non application content”. In the developer console I see that requests to save form data are sent not to localhost, but to the host name, and with a missing port (in this case 8080). If I open the form at its address (http://localhost:8080/users/new), then saving occurs correctly. Am I doing something wrong?