Project 5
Back-end Form Validation & Saving to a Database
Overview and Objective
In this project you will be adding to the form you created in the previous homework: your form will actually
submit its data to the server.
Once the server has received and validated the data, instead of just saying, ’Thanks!’ and then discarding it, your server will
actually save that data to a database. Of course, there’s no way for me to verify that your server is actually
saving the data unless you also provide a page to view that data, so you’ll do that too.
Technical Description and Instructions
1. Convert your website to use ExpressJS as per the instructions given in class
2. Configure Express to intercept both GET and POST requests coming in on the URL for your form
(a) On GET requests, the server should just render the form
(b) On POST requests, the server should validate all fields of the form and if everything is good
should redirect1 the user to a ’thank you’ page, otherwise the server should re-render the form
with the relevant errors pointed out to the user
Intercepting Requests To intercept the GET and POST requests coming in for the form, you should
first move the line which instructs express to serve the static pages of your website to the bottom of
your index.js file. Next, move your form into a directory called views which should be placed at the
top level of your website2 and rename it so that it ends with ’.ejs’. Finally, put ’server.get()’ and
’server.post()’ method calls in with the appropriate route and action for your form.
Rendering the Form Whether the form is rendered to the user ’plainly’ or with data verification and
extra prompting needs to be decided in the functions given to the server.get() and server.post()
calls. The form itself can contain the Embedded JavaScript code to render the error messages or not
based on whether or not certain attributes of the parameter object3 are defined or not (or are set to
true or false) which will be set by the previously mentioned functions.
Validating the Form Please ensure that the user has filled out all the fields with some answer and that
both the e-mail and the phone number are likely to be valid4.
Submission
Submit a zip of your website folder.
On POST requests for your form, the server should still validate all fields of the form as per the last project
and, if everything is good, it should then redirect1 the user to the page where all of the form submissions
can be viewed. To accomplish the saving the data to the database, you will first need to ensure that you
have done the following things:
1. Install sqlite3 on your system2
2. Install the sqlite3 plugin for node via ’npm install sqlite3’ in your project folder
3. Create an sqlite3 database file in your project directory using the sqlite3 command line interface3
Finally, you will need to hook your server up to the database4 as well as a new ’.ejs’ template for viewing
the form submissions that you must create.
Submission
Submit a zip of your website folder containing everything that lives at the top level of the website folder.
Grading Specification
For your submission to receive a grade of ‘pass’, it must fulfill the following criteria:
• It must be submitted appropriately
• The form should behave as described in the technical description and instructions section
1https://expressjs.com/en/api.html#res.redirect
2That is, where your index.js file is
3Called ’locals’
4Please do not just copy and paste some RegExp from the internet (that’s grounds for an academic integrity violation).