app.post('/register', (req, res) => {
console.log(req.body.name)
}
);
.container
.row
#registerBox.col-md-4.offset-md-4
form.form-signup(action='/register', method='POST')
.form-group
label Full Name
input.form-control(name='name', required='required', type='text')
.form-group
label Username
input.form-control(name='username', required='required', type='text')
.form-group
label Email
input.form-control(name='email', required='required', type='text')
.form-group
label Password
input.form-control(name='password', required='required', type='password')
.form-group
label Confirm Password
input.form-control(name='password2', required='required', type='password')
button.btn.btn-lg.btn-primary.btn-block(type='submit') Register
br
a.text-center.new-account(href='/login') Already have an account? Sign in.
第二部分是连接到节点的pug部分,但是由于console.log中的某种原因,它显示为未定义
答案 0 :(得分:0)
正如我看到的您发布的Pug代码一样,问题似乎出在提交按钮的缩进上。
应显示为:
.container
.row
#registerBox.col-md-4.offset-md-4
form.form-signup(action='/register', method='POST')
.form-group
label Full Name
input.form-control(name='name', required='required', type='text')
.form-group
label Username
input.form-control(name='username', required='required', type='text')
.form-group
label Email
input.form-control(name='email', required='required', type='text')
.form-group
label Password
input.form-control(name='password', required='required', type='password')
.form-group
label Confirm Password
input.form-control(name='password2', required='required', type='password')
button.btn.btn-lg.btn-primary.btn-block(type='submit') Register
br
a.text-center.new-account(href='/login') Already have an account? Sign in.
发生这种情况是因为提交的按钮类型必须在表单组件内部。否则,它不会被视为预期表单的提交按钮。