Tuesday, 4 April 2017

Register new 'etudiant'

Hello so i want to register a new user called 'etudiant' in my mongodb with a post request with

<form method="post" action="register">
          <h1>Create Account</h1>
            <div>
              <input type="text" class="form-control" placeholder="first_name" required="required" name="first_name"/>
            </div>
            <div>
              <input type="text" class="form-control" placeholder="last_name" required="required" name="last_name"/>
            </div>
            <div>
              <input type="text" class="form-control" placeholder="cin" required="required" name="cin"/>
            </div>
            <div>
              <input type="text" class="form-control" placeholder="adress" required="required" name="adress"/>
            </div>
            <div>
              <input type="text" class="form-control" placeholder="date_naissance" required="required" name="date_naissance"/>
            </div>
            <div>
              <input type="email" class="form-control" placeholder="Email" required="required" name="mail"/>
            </div>
            <div>
              <input type="password" class="form-control" placeholder="Password" required="required" name="pwd"/>
            </div>
            <div style="margin:auto;">
              <center><input type="submit" value="Register"></center>
            </div>
          </form>

and the controller for this form is

function register (req, res) {
//create etudiant
var etudiant{
  first_name:req.body.first_name,
  last_name:req.body.last_name,
  cin:req.body.cin,
  adress:req.body.adress,
  username:req.body.username,
  email:req.body.email,
  pwd:req.body.pwd
}
//use etudiant model to insert/save
  var newetudiant = new Etudiant(etudiant);
  //save etudiant
  newetudiant.save();

//redirect
res.redirect('/');

}

in the console i got this error that i don't find a solution for my error



via ghaieb sahbi

No comments:

Post a Comment