formparse
formparse [ -rE ] [ -o dir ] [ query ]
formparse
receives POST
data. Thus formparse
is used in conjugation with POST
method.-E
is used only for debugging purpose. Under this flag, formparse
will only echo the input.formparse
is needless.-r
” is no effect; the option was used to remove CR code but current formparse
always removes CR code except in accepting file.
In HTML, we have two types of encoding: application/x-www-form-urlencoded
and multipart/form-data
.
Formparse can handles both types by executing (without option) in CGI.
formparse
Assume we have following form:
<form method="POST" action="baz.cgi"> <input type="checkbox" name="foo" value="bar1">Bar1<br> <input type="checkbox" name="foo" value="bar2">Bar2<br> <input type="checkbox" name="foo" value="bar3">Bar3<br> <input type="reset" value="reset"> <input type="submit"> </form>and assume you checked Bar1 and Bar3 and then push “submit” button.
formparse
in baz.cgi and directory “/tmp/foo
” will be created with the following files:/tmp/foo/clone /tmp/foo/0 /tmp/foo/1These contents are “2”, “bar1” and “bar3” respectively.
You can confirm the above statement using the following CGI program.
#!/bin/rc echo Content-Type: text/plain echo formparse ls /tmp/foo for (x in /tmp/foo/*){ echo -n $x: cat $x echo }You can use other directory than “
/tmp
” by the option “-o dir
”.
Another important role of “formparse
” is receiving files.
Assume we use following HTML code:
<form enctype="multipart/form-data" method="POST" action="baz.cgi"> <input type="file" name="foo" size="60" multiple><br> <input type="reset" value="reset"> <input type="submit" value="send"><br> </form>
In HTML5, we have a new flag “multiple
” in input
tag in case type
is “file
”, which enables multiple selection of files using operations:
OSX: command + left_button
Win: ctrl + left_button
With this code, CGI will receive these files in /tmp/file/bar1
, /tmp/file/bar2
, ...
where bar1
, bar2
, ... are filenames that were selected.
Without “multiple
” flag, browsers does not allow multiple selection.
Content-Type: multipart/mixedThe format is obsoleted in HTML5.
http://plan9.aichi-u.ac.jp/netlib/cgitools/