Validating form data
Sanitizing data can help prevent malicious values from being displayed to users, but that doesn’t mean that the data you receive will be useful. Users will enter just about anything into a form, sometimes through genuine error, but mostly because forms are an unwelcome obstacle between the user and their goal, whatever that might be.
The result is that the data received from forms must be validated, which is the process of ensuring that data can be used by the application and telling the user when invalid data is received. Form validation is most easily done with a template because it makes it easy to give the user feedback when a problem arises. To prepare for validation, add a file named age.handlebars
to the templates/server
folder with the content shown in Listing 11.22.
Listing 11.22: The contents of the age.handlebars file in the templates/server folder
<div class="m-2">
{{#if nextage }}
<h4>Hello {{name...