The PiLLoW library provides some predicates which simplify the task of getting the input from a form. As we said before, this input can be provided in several ways, depending on the system and the method used to invoke the form, and is encoded with escape sequences. The principal predicates provided are:
For example, suppose we want to make a handler which implements a database of telephone numbers and is queried by a form including a single entry field with name person_name. The handler might be coded as follows:
#!/usr/local/bin/lpshell :- use_module('/usr/local/src/pillow/pillow.pl'). main(_) :- get_form_input(Input), get_form_value(Input,person_name,Name), write('Content-type: text/html'), nl, nl, write('<HTML><TITLE>Telephone database</TITLE>'), nl, write('<IMG SRC="phone.gif">'), write('<H2>Telephone database</H2><HR>'), write_info(Name), write('</HTML>'). write_info(Name) :- form_empty_value(Name) -> write('You have to provide a name.') ; phone(Name, Phone) -> write('Telephone number of <B>'), write(Name), write('</B>: '), write(Phone) ; write('No telephone number available for <B>'), write(Name), write('</B>.'). phone(daniel, '336-7448'). phone(manuel, '336-7435'). phone(sacha, '543-5316').
The code above is quite simple. On the other hand, the interspersion throughout the text of calls to write with HTML markup inside makes the code somewhat inelegant. Also, there is no separation between computation and input/output, as is normally desirable. It would be much preferable to have an encoding of HTML code as Prolog terms, which could then be manipulated easily in a more elegant way, and a predicate to translate such terms to HTML for output. This facility, provided by the PiLLoW library, is presented in the next section.