Great that you implemented client-side form validation with the required keyword on inputs. The next step would be validating the inputs on the server. At the moment, it's still possible to submit an empty form by removing the required keyword in the dev tools 😈
You could start with a basic check that the req.body object does not contain keys with empty string values before adding to your messages object:
// destructure name and text variables from req.body
// check that both name and text are truthy before adding to messages object
const { name, text } = req.body;
if (name && text) {
messages[uid] = req.body;
}
Then it would be nice to think of a way to inform the user - maybe redirect to a new page with an error message and a link back to the form? 🤔
Great that you implemented client-side form validation with the
required
keyword on inputs. The next step would be validating the inputs on the server. At the moment, it's still possible to submit an empty form by removing therequired
keyword in the dev tools 😈You could start with a basic check that the req.body object does not contain keys with empty string values before adding to your messages object:
Then it would be nice to think of a way to inform the user - maybe redirect to a new page with an error message and a link back to the form? 🤔