节点js中没有来自表单的请求 [英] No request from form in node js
问题描述
我正在使用两种形式的node js,express和handlebars.第一种形式用于登录,第二种形式用于注册新用户.它们几乎相似,但是第一个正在运行,第二个正在运行,不,我不知道为什么.
I'm working with node js, express and handlebars with two forms. The first form is for doing the login and the second one for registering the new user. They are almost similar but the first one is working and the second one, no and I don't know why.
这是来自register.hbr的代码
This is the code from register.hbr
<div class="login-page">
<div class="form">
<form class="login-form" name="register" method="POST" action="/register_success">
<input type="text" placeholder="email" required/>
<input type="password" placeholder="password" required/>
<input type="text" placeholder="nombre"/>
<input type="submit" value="Crear cuenta" name="register_success"></input>
<p class="message">Ya registrado? <a href="#">Entrar</a></p>
</form>
</div>
</div>
这是我在节点js中拥有的路由器
And this is the router that I've in node js
rutas.post('/register_success', (req, resp)=>{
console.log(req.body);
const email = req.body.email;
const nombre = req.body.name;
const password = req.body.password;
firebase.auth().createUserWithEmailAndPassword(email, password).then(user=>{
resp.send('Usuario creado con exito');
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
resp.render('loginError');
});
});
我的问题是,请求始终为空,IDK如何跟踪或查找问题.有帮助吗?
My issue is that the request is always empty and IDK how to trace or look for the problem. Any help?
推荐答案
最后我找到了问题. 问题是我没有命名输入,并且因为那个req.body是空的. 像这样重命名它们之后,一切正常.
Finally I found the issue. The proble is that I didn't name the inputs, and because of that req.body were empty. After renaming them like this, everything worked.
<input type="text" name="email" placeholder="email" required/>
<input type="password" name="password" placeholder="password" required/>
<input type="text" name="nombre" placeholder="nombre"/>
<input type="submit" value="Crear cuenta" name="register_success"> </input>
这篇关于节点js中没有来自表单的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!