Add href to a button in Pug without breaking a form


I’m trying to make my button href to my /leaderboard page after my quiz app submits.

    h1 Play Time 4 Trivia!
    button Go
            each val in questions
                        label= val.Question
                                option(value='true') True
                                option(value='false') False

        button(type="submit") Submit      

how would I go about having my submit button also redirect to another page without breaking my form submit?


You shouldn’t be doing this on the client side.

Say your form has action="/trivia", then at your Express server, assuming router is your Express app or a Router object:"/trivia", (req, res) => {
  // process the answers submitted in req.body
  // then when done:

The above also has the advantage that if the user refreshes the page, the form is not submitted another time.

Answered By – Old Geezer

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published