mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 06:14:59 +00:00
Estimated hours taken: 0.1 Branches: main, release extras/cgi/form_test.m: Conform to the breakup of std_util. Minor formatting and syntax changes.
62 lines
1.9 KiB
Mathematica
62 lines
1.9 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
|
|
% This is an example program to test the CGI library.
|
|
|
|
:- module form_test.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%----------------------------------------------------------------------------%
|
|
%----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module cgi.
|
|
:- import_module html.
|
|
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
:- import_module maybe.
|
|
|
|
%----------------------------------------------------------------------------%
|
|
|
|
% NOTE: you will need to change this to suit your system.
|
|
%
|
|
:- func my_url = string.
|
|
|
|
my_url = "http://hydra.cs.mu.oz.au/cgi-bin/mercury/form_test".
|
|
|
|
:- pred np(io::di, io::uo) is det.
|
|
|
|
np(!IO) :-
|
|
html.output_markup(np, !IO).
|
|
|
|
main(!IO) :-
|
|
cgi.get_form(MaybeFormEntries, !IO),
|
|
(
|
|
MaybeFormEntries = yes(FormEntries),
|
|
html.output_content_type_html(!IO),
|
|
html.output_header([title(text("Form Test"))], !IO),
|
|
html.output_markup(heading(1, text("Fields Entered:")), !IO),
|
|
io.print("<code>", !IO),
|
|
io.print(FormEntries, !IO),
|
|
io.print("</code>", !IO), np(!IO),
|
|
io.print("<pre>", !IO),
|
|
io.write_list(FormEntries, "\n", print, !IO),
|
|
io.print("</pre>", !IO), np(!IO),
|
|
html.output_form_start(my_url, !IO),
|
|
io.print("Name: ", !IO),
|
|
html.output_field("name", text(60, 90, ""), !IO), np(!IO),
|
|
io.print("Address: ", !IO),
|
|
html.output_field("address", textarea(3, 60, ""), !IO), np(!IO),
|
|
io.print("Bozo?", !IO),
|
|
html.output_field("bozo", checkbox(no, "yes"), !IO), np(!IO),
|
|
html.output_field("submit", submit("OK"), !IO), np(!IO),
|
|
html.output_form_end(!IO)
|
|
;
|
|
MaybeFormEntries = no
|
|
).
|