HTMLgen - an O'Caml HTML and CGI library

Version 0.2.2, 13 June 2000 David Clarke

Download the current release
 

Abstract

HTMLgen is an Objective Caml library for generating HTML and creating fill-in web forms. Forms generated by the library are initialized with the values from previous queries. It provides CGI support (via Gerd Stolpmann's netstring) and Cookies.

The following illustrates a typical use of the library:

  open Cgi
  open Html
  open Tagcore
  open Tagforms
  open Tagtables
  open Shortcut

  let smallf = font ~size:"-1"

  (* formats the CGI arguments into a table *)
  let format_args () =
    let arg = arguments () in
    let f b (s,a) = b << tr(td (lift s) << td (lift (arg_value a))) in
    let contents = List.fold_left f (lift "") arg in
      table ~attr:[`border 1] [contents]

  let mypage =
      header  <<
      page ~title:"A Typical Page" ~meta:["Author", "David Clarke"]
           ~attr:[`text "#009900"; `bgcolor "#FFFFCC"; `link "#3366FF";
                  `vlink "#993399"; `alink "#660000"] (
        h1 (lift "a place for arguments") <<
        hr ~attr:[`size "5"; `width "100%"] <<
        p <<
        form ~action:(this_url ())
             ~meth:"GET"
        (
          lift "Name:" <<
          text ~name:"name" ~attr:[`size "32"; `maxlength 80] << p <<
          lift "What pets do you own?" <<
          p << checkbox ~name:"pets" ~value:"dog" << lift "Dog" <<
          br << checkbox ~name:"pets" ~value:"cat" ~attr:[`checked] 
             << lift "Cat" <<
          br << checkbox ~name:"pets" ~value:"bird" << lift "Bird" <<
          br << checkbox ~name:"pets" ~value:"fish" << lift "Fish" <<
          p <<
          lift "Which pet is your favourite?" <<
          p << radio ~name:"favourite" ~value:"dog" << lift "Dog" <<
          br << radio ~name:"favourite" ~value:"cat" ~attr:[`checked] 
             << lift "Cat" <<
          br << radio ~name:"favourite" ~value:"bird" << lift "Bird" <<
          br << radio ~name:"favourite" ~value:"fish" << lift "Fish" <<
          p <<
          lift "Please make a comment:" <<
          br << textarea ~name:"comment" "Type your comment here" <<
          p << submit
        ) (* form *) <<
        p <<
        lift "This script was invoked with the following arguments:" <<
        format_args () ) (* page *)

  let _ = print (new_html () <<< mypage)
See the result of this script.

Contents