Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 213 lines (205 sloc) 6.866 kB
bd1a447 @tj More docs
tj authored
1 <a href="http://github.com/visionmedia/connect-form"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
2 <head>
3 <title>Connect Form</title>
4 <style>body {
5 margin: 0;
6 padding: 0;
7 font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
8 color: #252519;
9 }
10 a {
11 color: #252519;
12 }
13 a:hover {
14 text-decoration: underline;
15 color: #19469D;
16 }
17 p {
18 margin: 12px 0;
19 }
20 h1, h2, h3 {
21 margin: 0;
22 padding: 0;
23 }
24 ul#menu {
25 opacity: 0;
26 position: fixed;
27 top: 0;
28 right: 0;
29 list-style: none;
30 margin: 0;
31 padding: 10px 2px;
32 text-align: right;
33 background: rgba(255,255,255,0.7);
34 -webkit-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);
35 -moz-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);
36 -webkit-border-bottom-left-radius: 5px;
37 -moz-border-bottom-left-radius: 5px;
38 -webkit-transition-properties: opacity;
39 -webkit-transition-duration: 0.6s;
40 }
41 ul#menu:hover {
42 opacity: 1;
43 }
44 ul#menu li {
45 padding: 2px 10px;
46 border-bottom: 1px solid #eee;
47 }
48 ul#menu li:hover {
49 background: rgba(0,0,0,0.03);
50 }
51 ul#menu li:last-child {
52 border-bottom: none;
53 }
54 ul#menu li a {
55 text-decoration: none;
56 font-size: 12px;
57 color: rgba(0,0,0,0.5);
58 }
59 ul#menu li a strong {
60 font-weight: normal;
61 color: #252519;
62 }
63 table#source {
64 width: 100%;
65 border-collapse: collapse;
66 }
67 table#source td:first-child {
68 padding: 30px 40px 30px 40px;
69 vertical-align: top;
70 }
71 table#source td:first-child,
72 table#source td:first-child pre {
73 width: 450px;
74 }
75 table#source td:last-child {
76 padding: 30px 0 30px 40px;
77 border-left: 1px solid #E5E5EE;
78 background: #F5F5FF;
79 }
80 table#source tr {
81 border-bottom: 1px solid #E5E5EE;
82 }
83 table#source tr.filename {
84 padding-top: 40px;
85 border-top: 1px solid #E5E5EE;
86 }
87 table#source tr.filename td:first-child {
88 text-transform: capitalize;
89 }
90 table#source tr.filename td:last-child {
91 font-size: 12px;
92 }
93 table#source tr.filename h2 {
94 margin: 0;
95 padding: 0;
96 }
97 table#source tr.code h1,
98 table#source tr.code h2,
99 table#source tr.code h3 {
100 margin-top: 30px;
101 font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
102 font-size: 18px;
103 }
104 table#source tr.code h2 {
105 font-size: 16px;
106 }
107 table#source tr.code h3 {
108 font-size: 14px;
109 }
110 table#source tr.code ul {
111 margin: 15px 0 15px 35px;
112 padding: 0;
113 }
114 table#source tr.code ul li {
115 margin: 0;
116 padding: 1px 0;
117 }
118 table#source tr.code ul li p {
119 margin: 0;
120 padding: 0;
121 }
122 table#source tr.code td:first-child pre {
123 padding: 20px;
124 }
125 #ribbon {
126 position: absolute;
127 top: 0;
128 right: 0;
129 }
130 code .string { color: #219161; }
131 code .regexp { color: #219161; }
132 code .keyword { color: #954121; }
133 code .number { color: #19469D; }
134 code .comment { color: #bbb; }
135 code .this { color: #19469D; }</style>
136 </head>
137 <body>
138 <ul id="menu"><li><a href="#index.js"><strong>index</strong></a></li></ul><table id="source"><tbody><tr><td><h1>Connect Form</h1></td><td></td></tr><tr class="filename"><td><h2 id="index.js">index</h2></td><td>index.js</td></tr><tr class="code">
139 <td class="docs">
140 <p>Module dependencies.</p>
141 </td>
142 <td class="code">
143 <pre><code><span class="keyword">var</span> <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),
7d78c48 @tj index.html
tj authored
144 <span class="variable">formidable</span> = <span class="variable">require</span>(<span class="string">'formidable'</span>);</code></pre>
bd1a447 @tj More docs
tj authored
145 </td>
146 </tr>
147 <tr class="code">
148 <td class="docs">
149 <p>Setup form with the given <code>options</code>.</p>
150
151 <h2>Options</h2>
152
153 <ul>
154 <li><code>encoding</code> Encoding used for incoming forms. Defaults to utf8</li>
155 <li><code>uploadDir</code> Directory to save uploads. Defaults to &ldquo;/tmp&rdquo;</li>
156 <li><code>keepExtensions</code> Include original extensions. Defaults to <code>false</code></li>
157 </ul>
158
159
160 <h2>Examples</h2>
161
162 <pre><code> var form = require('connect-form');
163 var server = connect.createServer(
164 form({ keepExtensions: true }),
165 function(req, res, next){
166 // Form was submitted
167 if (req.form) {
168 // Do something when parsing is finished
169 // and respond, or respond immediately
170 // and work with the files.
ac57d4a @tj Release 0.1.0
tj authored
171 req.form.complete(function(err, fields, files){
bd1a447 @tj More docs
tj authored
172 res.writeHead(200, {});
173 if (err) res.write(JSON.stringify(err.message));
174 res.write(JSON.stringify(fields));
175 res.write(JSON.stringify(files));
176 res.end();
ac57d4a @tj Release 0.1.0
tj authored
177 });
bd1a447 @tj More docs
tj authored
178 // Regular request, pass to next middleware
179 } else {
180 next();
181 }
182 }
183 );
184 </code></pre>
185
186 <h2></h2>
187
188 <ul>
189 <li><p><strong>param</strong>: <em>Object</em> options</p></li>
190 <li><p><strong>return</strong>: <em>Function</em></p></li>
191 <li><p><strong>api</strong>: <em>public</em></p></li>
192 </ul>
193
194 </td>
195 <td class="code">
196 <pre><code><span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span>(<span class="variable">options</span>){
197 <span class="variable">options</span> = <span class="variable">options</span> || {};
198 <span class="keyword">return</span> <span class="keyword">function</span>(<span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">next</span>){
199 <span class="keyword">if</span> (<span class="variable">formRequest</span>(<span class="variable">req</span>)) {
ac57d4a @tj Release 0.1.0
tj authored
200 <span class="keyword">var</span> <span class="variable">callback</span> = <span class="keyword">function</span>(){},
201 <span class="variable">form</span> = <span class="variable">req</span>.<span class="variable">form</span> = <span class="keyword">new</span> <span class="variable">formidable</span>.<span class="class">IncomingForm</span>;
bd1a447 @tj More docs
tj authored
202 <span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">form</span>, <span class="variable">options</span>);
ac57d4a @tj Release 0.1.0
tj authored
203 <span class="variable">form</span>.<span class="variable">complete</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){ <span class="variable">callback</span> = <span class="variable">fn</span>; };
204 <span class="variable">form</span>.<span class="variable">parse</span>(<span class="variable">req</span>, <span class="keyword">function</span>(){
205 <span class="variable">callback</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);
206 });
bd1a447 @tj More docs
tj authored
207 }
ac57d4a @tj Release 0.1.0
tj authored
208 <span class="variable">next</span>();
bd1a447 @tj More docs
tj authored
209 };
210 };</code></pre>
211 </td>
212 </tr> </body>
213 </html></tbody></table>
Something went wrong with that request. Please try again.