Skip to content

Commit

Permalink
feat: use success and error view
Browse files Browse the repository at this point in the history
  • Loading branch information
filipezaidan committed Oct 3, 2024
1 parent 1674352 commit 4d1b567
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions routes/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ router.post("/", function (req, res) {
const errors = validateFormInput(req.body);

if (errors.length > 0) {
console.log({ errors });
return res.status(400).send({ errors });
const errorDetails = {
message: "Erro de validação",
status: 400,
fields: errors.map((err) => err.msg),
};
return res.status(400).render("error", { error: errorDetails });
}

return res.status(200).send("Formulário recebido com sucesso!");
return res.status(200).render("success");
});

module.exports = router;
5 changes: 2 additions & 3 deletions views/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
<input type="text" placeholder="Tel" >
<input type="text" placeholder="Ramal" >
</div>

<div class="clear"></div>

<label for="email">E-Mail:</label>
<input type="email" id="email" name="email">
<input type="text" id="email" name="email">
</fieldset>

<fieldset>
Expand All @@ -69,7 +68,7 @@
</select>

<label>Turno:</label>
<div class="radio-group">
<div class="radio-group">
<label for="morning" >Manhã</label>
<input type="radio" id="morning" name="shift" value="morning">
<label for="afternoon" >Tarde</label>
Expand Down

0 comments on commit 4d1b567

Please sign in to comment.