Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<html>
2
<head>
3
<title>html2ps/html2pdf interactive forms</title>
4
<link rel="stylesheet" type="text/css" medial="all" title="Default" href="css/help.css"/>
5
</head>
6
<body>
7
<h1>html2ps/pdf interactive forms</h1>
8
<a href="index.html">Back to table of contents</a>
9
 
10
<h2>Difference between forms in HTML and PDF</h2>
11
<p>I guess, if you use html2ps script, then you know how forms are defined in HTML and how form data is sent using the POST format. This script
12
tries to emulate the browser behavior as closely as possible; nevertheless, there's several important differences.
13
 
14
<h3>Field names are required</h3>
15
<p>In HMTL, you may write an INPUT tag without &quot;name&quot; attribute and get working interactive control; often, submit and reset buttons
16
are written this way. When using html2ps interactive forms, you <strong>must</strong> provide &quot;name&quot; attribute for all
17
controls which should be rendered interactive. If you don't do it, the control will be rendered as a graphic like "Interactive forms" options
18
disabled.
19
 
20
<h3>Field names should be unique</h3>
21
<p>In HTML you usually <i>may</i> enter several controls with the same name into the same form and get
22
some kind of results. PDF files do not allow such fields at all. In this case, all subsequent fields
23
sharing the same name will be rendered as non-interactive.
24
</p>
25
 
26
<h3>Form &amp field names</h3>
27
<p>Unlike HTML, the parameter names in POST request are not the field names. Acrobat Reader uses a &quot;fully qualified field names&quot;
28
instead. It means that field is identified by composite string having the form
29
<pre class="code">
30
&lt;form name&gt;.&lt;field name&gt;
31
</pre>
32
(See also <em>PDF Reference 1.6 Fifth Edition, pp.638&ndash;639</em>
33
for more precise and detailed explanation). When posting data in POST format, dots are converted to underscores, so you would get:
34
<pre class="code">
35
&lt;form name&gt;_&lt;field name&gt;
36
</pre>
37
when processing the POSTed data.
38
</p>
39
 
40
<p>To illustrate what I've said above, consider the following example:
41
<pre class="code">
42
&lt;form name=&quot;form1&quot;&gt;
43
&lt;input type=&quot;text&quot; name=&quot;item1&quot; value=&quot;test&quot;/&gt;
44
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit 1st form&quot;/&gt;
45
&lt;/form&gt;
46
 
47
&lt;form name=&quot;form2&quot;&gt;
48
&lt;input type=&quot;text&quot; name=&quot;item2&quot; value=&quot;test&quot;/&gt;
49
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit 2nd form&quot;/&gt;
50
&lt;/form&gt;
51
</pre>
52
Usually you would get POST variables &quot;item1&quot; and &quot;submit&quot; when submitting the 1st form and
53
&quot;item2&quot; and &quot;submit&quot; when submitting the 2nd form. When submitting the form from PDF, you'll get
54
&quot;form1_item1&quot;, &quot;form1_submit&quot; and &quot;form2_item2&quot;, &quot;form2_submit&quot; correspondingly.
55
 
56
</p>
57
 
58
<p>The name of the form is taken from &quot;name&quot; or &quot;id&quot; FORM tag attributes (note that if both attributes are specified, then
59
&quot;name&quot; have the higher priority). If both these attributes are missing, then the script attemts to generate an unique name for the form;
60
Newertheless, it is <strong>highly</strong> recommended to add &quot;id&quot; or &quot;name&quot; attributes for every form definition. The
61
autogenerated form names may suddenly change when you change the page content. It is not guaranteed that future html2ps versions will
62
use the same name generation rules.</p>
63
 
64
<p>Also, you must note that html2ps is less tolerant to the form definition than most browsers. You may get conversion errors or even
65
unpredictable results when viewing generated PDF if the following conditions are not satisfied:
66
<ul>
67
<li>Form names are unique throughout the page</li>
68
<li>Field names are unique in the form</li>
69
<li>Radio button values are unique inside the button group</li>
70
</ul>
71
</p>
72
 
73
<h3>Button field values</h3>
74
<p>
75
In HTML, when you click on the Submit button, the posted data will include the value of &quot;value&quot; attribute for the button.
76
When you're submitting form from generated PDF, you'll get an <strong>empty string</strong> as a value of this parameter. Thus,
77
this check is a bad idea (bad, but rather popular):
78
<pre class="code">
79
&hellip;
80
if ($_POST['my_submit_button_name']) {
81
&hellip;
82
</pre>
83
and should be replaced by this code:
84
<pre class="code">
85
&hellip;
86
if (isset($_POST['my_submit_button_name'])) {
87
&hellip;
88
</pre>
89
</p>
90
 
91
<h3>Image submit button click coordinates</h3>
92
<p>
93
In HTML forms, you'll get three POST varaibles after clicking on "image" submit button: &lt;button&gt;, &lt;button&gt;_x and &lt;button&gt;_y.
94
When you're posting data from PDF you'll get only two last parameters!
95
</p>
96
 
97
<h3>Unsupported field types</h3>
98
<p>
99
&quot;file;&quot; and &quot;hidden&quot; fields are not supported.
100
</p>
101
 
102
<h2>Server-side form handling</h2>
103
 
104
<strong>Note:</strong> there's an PHP extension designed to work with FDF files; you may wish to check documentation at
105
        PHP.net: <a title="Opens in new window" target="_blank" href="http://php.net/manual/en/ref.fdf.php">Forms Data Format Functions</a>
106
 
107
<p>Basically, you must use the script which accepts data in HTTP POST format and outputs result in FDF format. (Actually, in any format,
108
but be prepared to Acrobat Reader complaints like &quot;Cannot handle Content-Type: &hellip;&quot;)
109
The minimal data-handling example is:
110
<pre class="code">
111
// output an empty FPF file
112
 
113
$outfdf  = fdf_create();
114
$tmpname = tempnam('../temp',"FDF_");
115
fdf_set_status($outfdf, "Thank you!");
116
fdf_save($outfdf, $tmpname);
117
fdf_close($outfdf);
118
 
119
fdf_header();
120
$fp = fopen($tmpname, "r");
121
fpassthru($fp);
122
unlink($tmpname);
123
</pre>
124
It just confirms the receiving of the posted data; &quot;Thank you!&quot; message will be shown as a popup by Acrobat Reader.
125
Probably you would want to actually do something with POSTed data, but is it far beyound the area of this manual.
126
 
127
<h2>Compatibility list</h2>
128
<table>
129
<thead>
130
<tr class="odd">
131
<th>Element</th>
132
<th>Is supported?</th>
133
<th>Notes</th>
134
</tr>
135
</thead>
136
 
137
<tbody>
138
<tr class="even">
139
<td>Text field (&lt;input type="text"&gt;)</td>
140
<td class="yesno">Yes</td>
141
<td></td>
142
</tr>
143
 
144
<tr class="odd">
145
<td>Password field (&lt;input type="password"&gt;)</td>
146
<td class="yesno">Yes</td>
147
<td></td>
148
</tr>
149
 
150
<tr class="even">
151
<td>Submit button (&lt;input type="submit"&gt;)</td>
152
<td class="yesno">Yes</td>
153
<td>Value of button "value" attribute is not posted</td>
154
</tr>
155
 
156
<tr class="odd">
157
<td>Reset button (&lt;input type="reset"&gt;)</td>
158
<td class="yesno">Yes</td>
159
<td></td>
160
</tr>
161
 
162
<tr class="even">
163
<td>Plain button (&lt;input type="button"&gt;)</td>
164
<td class="yesno">Yes</td>
165
<td>Renders and you may click on them, but there's no much use of buttons, as Javascript is NOT supported</td>
166
</tr>
167
 
168
<tr class="odd">
169
<td>Checkbox (&lt;input type="checkbox"&gt;)</td>
170
<td class="yesno">Yes</td>
171
<td></td>
172
</tr>
173
 
174
<tr class="even">
175
<td>Radio (&lt;input type="radio"&gt;)</td>
176
<td class="yesno">Yes</td>
177
<td></td>
178
</tr>
179
 
180
<tr class="odd">
181
<td>Textarea (&lt;textarea&gt;)</td>
182
<td class="yesno">Yes</td>
183
<td></td>
184
</tr>
185
 
186
<tr class="even">
187
<td>Select (&lt;select&gt;)</td>
188
<td class="yesno">Yes</td>
189
<td></td>
190
</tr>
191
 
192
<tr class="odd">
193
<td>Image (&lt;input type="image"&gt;)</td>
194
<td class="yesno">Yes</td>
195
<td></td>
196
</tr>
197
 
198
<tr class="even">
199
<td>File (&lt;input type="file"&gt;)</td>
200
<td class="yesno">No</td>
201
<td></td>
202
</tr>
203
 
204
<tr class="odd">
205
<td>Hidden (&lt;input type="hidden"&gt;)</td>
206
<td class="yesno">No</td>
207
<td></td>
208
</tr>
209
 
210
</tbody>
211
 
212
</table>
213
 
214
</body>
215
</html>