forked from erlyaws/yaws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.yaws
66 lines (54 loc) · 1.89 KB
/
post.yaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<erl>
box(Str) ->
{'div',[{class,"box"}],
{pre,[], yaws_api:htmlize(Str)}}.
fpostvar(A, Key) ->
case postvar(A,"lang") of
undefined -> "None";
{ok, Val} ->
Val
end.
out(A) ->
[{ssi, "TAB.inc", [],[]},
{ehtml,
{'div',[{id, "entry"}], [{h2, [],"post.yaws"},
{p,[],[ "This is the ", {tt, [], "post.yaws"}, " file ",
"This yaws file gets invoked with POSTed client data. "
"This is the data that is submitted from the forms page ",
{a, [{href, "form.yaws"}], " form.yaws "}]},
{p, [], ["POST data is naturally organized as a ",
{tt, [], "{Key, Value} "}, " list. A call to "
"the function ", {tt, [], "yaws_api:parse_post(A) "},
" will parse the POSTed data. and return a key/value list "]},
box("
out(A) ->
{ehtml,
{pre, [],
io_lib:format('~p', [yaws_api:parse_post(A)])}}.
"),
{p, [], "Produces the following output"},
box(io_lib:format('~p', [yaws_api:parse_post(A)])),
{p, [], ["The natural way to extract the \"Variables\" from "
" the posted data is to use the function (defined in yaws_api.erl) "
" called ", {tt,[], "postvar(Arg,Key) "}]},
{p, [], "Thus the following erlang code: "},
box("
out(A) ->
{ehtml,
{p,[], [\"The favourite programming language is \",
case postvar(A,\"lang\") of
undefined -> \"None\";
{ok, Val} -> Val
end]}}.
"),
{p,[], "Produces the following output:"},
{hr,[],[]},
{'div',[{class,"box"}],
{p,[], ["The favourite programming language is ",
case postvar(A,"lang") of
undefined -> "None";
{ok, Val} -> Val
end]}}
]}},
{ssi, "END",[],[]}].
</erl>