Did you know ... Search Documentation:
Pack weblog -- prolog/html_form/html_form.pl
PublicShow source

This module handles the common web task of creating a form, validating the input, and, if not valid, redirecting the user back to the form with error messages over the offending elements

So, say the form is

   name: [       ]
   age:  [     ]
   (Submit)

The user enters their name but leaves their age blank.

they next see

   name:  [Sally Smith]
   You need to enter an age:
   age:   [    ]
   (Submit)

They enter their age and click submit. They land on a landing page:

   Thank you for your personal info. We'll be sure
   to enter it in our database and as a bonus we'll
   make sure it gets entered in many others throughout
   the globe.
        (Home)

To implement this example we would define a handler

:- http_handler(root(spamform) , spam_page_handler, [id(spamform)]).

spam_page_handler(Request) :-
        validated_form(
            reply_html_page(
                web_style,
                [title('A little problem....')],
                login_form(Request)),
            reply_html_page(
                web_style,
                [title('Thanks'),
                spam_landing_page_content(Request))).

and then in login_form you do something like

login_form(Request) -->
 ....
      form([action='/spamform', method=POST], [
             \(html_form:error_message([for=name], p([class=oops], 'you have to type a name'))),
             \(html_form:form_field(Request, length_input_minmax(3, '>'), input([name=name, type=textarea], []))),
             \(html_form:error_message([for=age], p([class=oops], 'Problem with age'))),
             \(html_form:form_field(Request, numeric_minmax(14, '>'), input([name=age, type=textarea], [])))
                                               ....]
author
- Anne Ogborn
license
- LGPL
 form_invalidate is det
always unifies, side effect is marking the form as invalid.
 form_field(+Request:list, :Validator:term, +FormField)// is semidet
unifies when form validates

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 validated_form(Arg1, Arg2)
 error_message(Arg1, Arg2, Arg3, Arg4)
 length_input_minmax(Arg1, Arg2)
 numeric_minmax(Arg1, Arg2)
 value(Arg1)
 length_input_minmax(Arg1, Arg2, Arg3, Arg4, Arg5)
 numeric_minmax(Arg1, Arg2, Arg3, Arg4, Arg5)
 value(Arg1, Arg2, Arg3, Arg4)