Generate error messages based on whether or not data was supplied in a form submit, checking req.body to do so.
Prevent duplicate data from being added into the database. Generate error messages if certain data submitted through a form already exists in the database.
Use an error array to contain only the errors that apply during a form submission.
Complete the exercise to demonstrate your ability to do the objectives above
Understand error handling using next(err)
routes/index.js
views/index.hbs
The errors array will contain the correct errors because you pushed only the errors that applied
Validations with Knex
Validations with Knex
Check if the name exists in the database, if knex returns data to you, re-render the new.hbs file with an error message.
Otherwise, you can insert the form data (req.body)
Combining form validation and Knex validation
Combining form validation and Knex validation
All errors render correctly
When making post requests, res.render is usually used when re-rendering a page and passing in error messages
Text
res.render vs res.redirect with validations
Text
When making post requests, res.redirect is generally used after inserting data into a database, and then redirecting to the page that displays all of the database items
If you return next(new Error("some error"))
Express will render the error.hbs file and populate it with the error message you specified
Objectives
Generate error messages based on whether or not data was supplied in a form submit, checking req.body to do so.
Use an error array to contain only the errors that apply during a form submission.
Use an error array to contain only the errors that apply during a form submission.
Complete exercise to demonstrate your ability to do the objectives above
Prevent duplicate data from being added into the database. Generate error messages if data submitted through a form already exists in the database.
Generate success message on successful database insertion
Extra Challenge
Answer questions in WRITEHERE.md before submitting a pull request
Understand error handling using next(err)
https://github.com/gSchool/expressValidations
A link to the slides is available in the repo for reference