I have a form where a user enters their email, password and class. I send the user the HTML file from node.js using:
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/Login-Signup.html'));
});
I think get the variables from the form using:
var email = req.body.email;
var password = req.body.password;
var cpassword = req.body.cpassword;
var userclass = req.body.userclass;
This is how my HTML form is set out:
<form method="post">
<fieldset>
<div class="formTitle">Account Sign Up</div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" />
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password" />
<label for="cpassword">Confirm Password:</label>
<input type="password" id= "cpassword" name="cpassword" placeholder="Confirm password"/>
<label for="class">Class:</label>
<input id="text" id= "class" name="userclass" placeholder="Enter your class"/>
<input type="submit" formmethod="post" formaction="/" value="Submit Details">
</fieldset>
</form>
When the values have been entered, the variables must pass a few checks to see if they are valid. They are laid out as so:
app.post('/', function(req, res){
function emailCheck(email){
//when theres an error: console.log(error), and return false
}
function passCheck(password){
//when theres an error: console.log(error), and return false
}
if (passCheck == true && emailCheck == true){
//enter user into database
}
}
When the email or password is not valid (to my checks) I want an alert box to appear, displaying the problem. I've looked into using AJAX, experimenting with the code but nothing seems to work for me. Is it the way I'm collecting the variables from the HTML? Is it how my get/post commands are laid out?
Thanks in advance.
PS; I am using express.