title: Express JS form validation with hapi/Joi doesn't validate form data correctly
body: <p>I have a form which i'm trying to validate using the hapi/Joi package, but it doesn't take values from the form. Instead it returns the first validation error because all schema keys take the value of "undefined". How can I solve this problem? Also is there a way to print out errors to the user without refreshing the page in Express? If yes please let me know about it.</p>
  
  <p>My Express code:</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const path = require('path');
  const bodyParser = require('body-parser');
  const Joi = require('@hapi/joi');
  const uuidv4 = require('uuid/v4');
  
  app.set('view engine','ejs');
  
  const urlEncodedParser = app.use(bodyParser.urlencoded({extended:false}));
  app.use(bodyParser.json());
  
  app.use(express.static(path.join(__dirname + '/public')));
  
  app.get('/',(req,res)=&gt;{
      res.render('main');
  });
  
  const schema = Joi.object().keys({
      name: Joi.string().min(3).required(),
      surname: Joi.string().min(5).required(),
      age: Joi.number().integer(),
      email: Joi.string().email({minDomainSegments: 2}).required(),
      password: Joi.string().min(3).required(),
      confirm: Joi.any().valid(Joi.ref('password'))
  });
  
  app.post('/register',(req,res)=&gt;{
      req.body.id = uuidv4();
      console.log(req.body);
      const result = Joi.validate({
  
          name: req.body.name,
          surname: req.body.surname,
          age: req.body.age,
          email: req.body.email,
          password: req.body.password,
          confirm: req.body.confirm
  
      }, schema,(error,value)=&gt;{
          if(error){
  
              printError(error);
  
          }
          else{
              console.log('success');
          }
      });
  
  });
  
  function printError(error){
      console.log(error);
  }
  
  app.listen(3000);
  </code></pre>
  
  <p>My form:</p>
  
  <pre><code>&lt;form action="/register" method="POST" enctype="multipart/form-data"&gt;
  
          &lt;input type="text" name='name' class="form-control" value=""&gt;
          &lt;input type="text" name='surname' class="form-control" value=""&gt;
          &lt;input type="number" name='age' class="form-control" value=""&gt;
          &lt;input type="email" name='email' class="form-control" value=""&gt;
          &lt;input type="password" name='password' class="form-control"&gt;
          &lt;input type="password" name='confirm' class="form-control"&gt;
          &lt;input type="submit" class="btn btn-block btn-success" value="OKAY"&gt;
  
      &lt;/form&gt;
  </code></pre>
  
  <p>The error which I get:</p>
  
  <pre><code>{ ValidationError: child "name" fails because ["name" is required]
      at Object.exports.process (C:\xampp\htdocs\express+mongo\node_modules\@hapi\joi\lib\errors.js:202:19)
      at internals.Object._validateWithOptions (C:\xampp\htdocs\express+mongo\node_modules\@hapi\joi\lib\types\any\index.js:763:31)
      at module.exports.internals.Any.root.validate (C:\xampp\htdocs\express+mongo\node_modules\@hapi\joi\lib\index.js:145:23)
      at app.post (C:\xampp\htdocs\express+mongo\index.js:31:24)
      at Layer.handle [as handle_request] (C:\xampp\htdocs\express+mongo\node_modules\express\lib\router\layer.js:95:5)
      at next (C:\xampp\htdocs\express+mongo\node_modules\express\lib\router\route.js:137:13)
      at Route.dispatch (C:\xampp\htdocs\express+mongo\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (C:\xampp\htdocs\express+mongo\node_modules\express\lib\router\layer.js:95:5)
      at C:\xampp\htdocs\express+mongo\node_modules\express\lib\router\index.js:281:22
      at Function.process_params (C:\xampp\htdocs\express+mongo\node_modules\express\lib\router\index.js:335:12)
    isJoi: true,
    name: 'ValidationError',
    details:
     [ { message: '"name" is required',
         path: [Array],
         type: 'any.required',
         context: [Object] } ],
    _object:
     { name: undefined,
       surname: undefined,
       age: undefined,
       email: undefined,
       password: undefined,
       confirm: undefined },
    annotate: [Function] }
  </code></pre>
  
  <p>It says "name is required" even when i'm filling in the name input in my form and hitting enter.</p>