Multi-page forms in Node.js -
i'm working on project i'd split form on multiple pages.
we're using express node.js.
would possible store variable 1 page , continue pass along subsequent pages?
the first page called "signup" directs "instructions." code snippit instructions follows:
app.post('/instructions', function(req, res){ res.render('instructions.ejs', {book-code=req.body.book-code, pages=req.body.pages, author=req.body.author, title=req.body.title}); });
the hidden form on instructions.ejs page looks like:
<form action = "record" method="post"> <input type="hidden" name="iauthor" value="author"> <input type="hidden" name="ipages" value="pages"> <input type="hidden" name="ibook-code" value="book-code"> <input type="hidden" name="ititle" values="title"> </form>
then, section record ejs file is:
app.post('/record', function(req, res){ pg.connect(process.env.database_url, function(err, client, done) { client.query('insert database(book, pages, name, title) values($1)', [req.body.ibook-code, req.body.ipages, req.body.iauthor, req.body.ititle], function(err, result) { if(err) return console.error(err); console.log(result.rows); }); }); res.render('record.ejs'); });
Comments
Post a Comment