Warning: Reason support is experimental. We are looking for beta-tester and contributors.

How to write forms?

To write an HTML form towards an Eliom service

The syntax is the same as for links, for instead of the content of the form, it takes a function that will generate the content from parameter names. Example:

let create_form =
  (fun (number_name, (number2_name, string_name)) ->
    [p [pcdata "Write an int: ";
        Html5.D.int_input ~input_type:`Text ~name:number_name ();
        pcdata "Write another int: ";
        Html5.D.int_input ~input_type:`Text ~name:number2_name ();
        pcdata "Write a string: ";
        Html5.D.string_input ~input_type:`Text ~name:string_name ();
        Html5.D.string_input ~input_type:`Submit ~value:"Click" ()]])

let form = register_service ["form"] unit
  (fun () () ->
     let f = Html5.D.get_form coucou_params create_form in
         (head (title (pcdata "")) [])
         (body [f])))

POST forms may also take get parameters, as last argument of function post_form:

  (fun chaine ->
    p [pcdata "Write a string: ";
       string_input ~input_type:`Text ~name:chaine ()])

Raw forms

There is also a raw interface to write basic forms without Eliom, using standard tyxml constructors.

Use module Eliom_content_core.Html5.D.Raw.