node.js - How to pass param using query or route through a form? -


form(action='/allusers', method="post")     input(id='name', placeholder='first name / last name')         button(type='submit') launch spacecraft 

this html(jade) redirects allusers page page takes user name input cant pass 'name' allusers

router.post('/allusers', function(req, res, next) { var name = req.query.name; console.log(name); res.render('allusers', { title: 'all users' }); }); 

not mention, have tired using req.param.name seems work req.body.name want know how use req.param and\or req.query because cant change url form submit extract information it

edit1: kind of solve issue in defining form , suppose input(type='',name='', placeholder='') , using req.body.name still dont know how play url yet

edit: didn't noticed sing id attribute instead of name right 1 defining form field names.

id identifying (not inputs) dom elemnts in dom context. field names should specified name attribute. why (as figured out, didn't answered me yet), when submit form you don't see "name=xxxx" in url.

orignal (in case wrong) answer):

in requests, form data (actual url parameters) come in req.query property (not req.params said before edit, sorry).

fixed example:

app.get('/user', function(req, res) {   res.send('user ' + req.query.name); }); 

anyway, see express request.query documentation.

actually, according http specification, url parameters can provided in post, put, delete or patch requests. why come in different place: because can have url parameters when submitting form thought post, put, delete, patch (or other specified in future) request.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -