Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tag: 0.1.1
Fetching contributors…

Cannot retrieve contributors at this time

213 lines (205 sloc) 6.866 kB
<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>
<head>
<title>Connect Form</title>
<style>body {
margin: 0;
padding: 0;
font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
color: #252519;
}
a {
color: #252519;
}
a:hover {
text-decoration: underline;
color: #19469D;
}
p {
margin: 12px 0;
}
h1, h2, h3 {
margin: 0;
padding: 0;
}
ul#menu {
opacity: 0;
position: fixed;
top: 0;
right: 0;
list-style: none;
margin: 0;
padding: 10px 2px;
text-align: right;
background: rgba(255,255,255,0.7);
-webkit-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);
-moz-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);
-webkit-border-bottom-left-radius: 5px;
-moz-border-bottom-left-radius: 5px;
-webkit-transition-properties: opacity;
-webkit-transition-duration: 0.6s;
}
ul#menu:hover {
opacity: 1;
}
ul#menu li {
padding: 2px 10px;
border-bottom: 1px solid #eee;
}
ul#menu li:hover {
background: rgba(0,0,0,0.03);
}
ul#menu li:last-child {
border-bottom: none;
}
ul#menu li a {
text-decoration: none;
font-size: 12px;
color: rgba(0,0,0,0.5);
}
ul#menu li a strong {
font-weight: normal;
color: #252519;
}
table#source {
width: 100%;
border-collapse: collapse;
}
table#source td:first-child {
padding: 30px 40px 30px 40px;
vertical-align: top;
}
table#source td:first-child,
table#source td:first-child pre {
width: 450px;
}
table#source td:last-child {
padding: 30px 0 30px 40px;
border-left: 1px solid #E5E5EE;
background: #F5F5FF;
}
table#source tr {
border-bottom: 1px solid #E5E5EE;
}
table#source tr.filename {
padding-top: 40px;
border-top: 1px solid #E5E5EE;
}
table#source tr.filename td:first-child {
text-transform: capitalize;
}
table#source tr.filename td:last-child {
font-size: 12px;
}
table#source tr.filename h2 {
margin: 0;
padding: 0;
}
table#source tr.code h1,
table#source tr.code h2,
table#source tr.code h3 {
margin-top: 30px;
font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
font-size: 18px;
}
table#source tr.code h2 {
font-size: 16px;
}
table#source tr.code h3 {
font-size: 14px;
}
table#source tr.code ul {
margin: 15px 0 15px 35px;
padding: 0;
}
table#source tr.code ul li {
margin: 0;
padding: 1px 0;
}
table#source tr.code ul li p {
margin: 0;
padding: 0;
}
table#source tr.code td:first-child pre {
padding: 20px;
}
#ribbon {
position: absolute;
top: 0;
right: 0;
}
code .string { color: #219161; }
code .regexp { color: #219161; }
code .keyword { color: #954121; }
code .number { color: #19469D; }
code .comment { color: #bbb; }
code .this { color: #19469D; }</style>
</head>
<body>
<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">
<td class="docs">
<p>Module dependencies.</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),
<span class="variable">formidable</span> = <span class="variable">require</span>(<span class="string">'formidable'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Setup form with the given <code>options</code>.</p>
<h2>Options</h2>
<ul>
<li><code>encoding</code> Encoding used for incoming forms. Defaults to utf8</li>
<li><code>uploadDir</code> Directory to save uploads. Defaults to &ldquo;/tmp&rdquo;</li>
<li><code>keepExtensions</code> Include original extensions. Defaults to <code>false</code></li>
</ul>
<h2>Examples</h2>
<pre><code> var form = require('connect-form');
var server = connect.createServer(
form({ keepExtensions: true }),
function(req, res, next){
// Form was submitted
if (req.form) {
// Do something when parsing is finished
// and respond, or respond immediately
// and work with the files.
req.form.complete(function(err, fields, files){
res.writeHead(200, {});
if (err) res.write(JSON.stringify(err.message));
res.write(JSON.stringify(fields));
res.write(JSON.stringify(files));
res.end();
});
// Regular request, pass to next middleware
} else {
next();
}
}
);
</code></pre>
<h2></h2>
<ul>
<li><p><strong>param</strong>: <em>Object</em> options</p></li>
<li><p><strong>return</strong>: <em>Function</em></p></li>
<li><p><strong>api</strong>: <em>public</em></p></li>
</ul>
</td>
<td class="code">
<pre><code><span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span>(<span class="variable">options</span>){
<span class="variable">options</span> = <span class="variable">options</span> || {};
<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>){
<span class="keyword">if</span> (<span class="variable">formRequest</span>(<span class="variable">req</span>)) {
<span class="keyword">var</span> <span class="variable">callback</span> = <span class="keyword">function</span>(){},
<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>;
<span class="variable">utils</span>.<span class="variable">merge</span>(<span class="variable">form</span>, <span class="variable">options</span>);
<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>; };
<span class="variable">form</span>.<span class="variable">parse</span>(<span class="variable">req</span>, <span class="keyword">function</span>(){
<span class="variable">callback</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);
});
}
<span class="variable">next</span>();
};
};</code></pre>
</td>
</tr> </body>
</html></tbody></table>
Jump to Line
Something went wrong with that request. Please try again.