Logo address

formparse

NAME

	formparse

SYNOPSIS

	formparse [ -rE ] [ -o dir ] [ query ]

DESCRIPTION

formparse receives POST data. Thus formparse is used in conjugation with POST method.
Flag -E is used only for debugging purpose. Under this flag, formparse will only echo the input.
The argument query is holdover in the age of old version of Pegasus. Current Pegasus processes query string internally and that means query of formparse is needless.
The flag “-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

application/x-www-form-urlencoded

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.
The submitted data will be received by formparse in baz.cgi and directory “/tmp/foo” will be created with the following files:
	/tmp/foo/clone
	/tmp/foo/0
	/tmp/foo/1
These 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”.

multipart/form-data

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.


NOTE: Formparse does not support old format
	Content-Type: multipart/mixed
The format is obsoleted in HTML5.
My testing shows that Chrome, Firefox, Safari, Opera and even IE11 do not send files using this old format. (2014/12/11)


BUGS

Not known.
However Formparse was written in old days and the internal code is dirty. It is better to be rewritten.

SOURCE

http://plan9.aichi-u.ac.jp/netlib/cgitools/