I'm creating a candidate registration page where the candidate should enter his details to get registered but I also want to show an error message if he misses to enter any field in the frontend and send back to the registration page saying "You need to fill all details". Any help will be appreciated!
This is controller
routes.post('/CreateCandidate' (req, res) => {
var { ConsultantName, Location, job role, job type, Salary, Salarytype, experience, Availability, Skills, VisaStatus, BillingRate, resume } = req.body;
console.log('okay');
console.log(req.file);
var Skills = req.body.Skills.split(',');
Skills = Skills.map(function(x){ return x.toUpperCase() });
var Candidateresume = req.file.filename;
var author = req.user.email;
Candidate({
author,
ConsultantName,
Location,
JobRole,
jobtype,
Salary,
Salarytype,
experience,
Availability,
Skills,
VisaStatus,
BillingRate,
resume
}).save((err, data) => {
res.redirect('/MyCandidates');
});
});
frontend is
<form action="/CreateCandidate" method="POST" enctype="multipart/form-data">
<div class="form-group row">
<h4><strong>ConsultantName</strong></h4>
<input type="text" class="form-control" name="ConsultantName" id="ConsultantName"
autocomplete="off" >
<h4><strong>Location</strong></h4>
<input type="text" class="form-control" name="Location" id="Location"
autocomplete="off" placeholder="Enter Location">
<h4><strong>Job Role</strong></h4>
<input type="text" class="form-control" name="Job Role" id="JobRole"
autocomplete="off" placeholder="Ex Java Developer">
// Other Fields to input data
<button type="submit"</button>
</div>
</form>
Olalekan Adekola
Software Engineer
Hello, have you found a solution to this yet?
I'll look into one of my express/ejs repos and recommend a solution soon.