Last active
June 12, 2016 18:34
-
-
Save DylanPiercey/3a07786eed83950b13b8 to your computer and use it in GitHub Desktop.
An isomorphic Rill snippet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use an isomorphic form-data/body parser. | |
app.use(require("@rill/body")()); | |
// Register our form page route as normal. | |
app.get("/my-form-page", ({ req, res })=> { | |
res.body = <MyForm/> | |
}); | |
// Setup our post route. | |
app.post("/my-form-submit", ({ req, res })=> { | |
// Analyze the response body (works in node and the browser) | |
req.body; //-> { email: ... } | |
req.files; // Any files submitted with the form. | |
// Perform the business logic (typically calling some api) | |
... | |
// Finally take the user somewhere meaningful. | |
res.redirect("/thank-you"); | |
}); | |
function MyForm (props) { | |
return ( | |
<html> | |
<head> | |
<title>My App - Form</title> | |
</head> | |
<body> | |
Please, your data is important for my business! | |
<form action="/my-form-submit" method="POST"> | |
Email: <input name="email"> | |
<button type="submit">Subscribe</button> | |
</form> | |
<a href="/">Take me back!</a> | |
<script src="/app.js"/> | |
</body> | |
</html> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment