0

I was woundering how to forward user selected html (radios and checkboxes) that is posted by a user as isbst365体育投注网址大全 to a newly rendered website using nodejs

That means user selected radio buttons and checkboxes, as well as unselected buttons and radios would be as per user selection and with the html tags

New contributor
Rashid Al Barwani is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Can you be more clear/detailed on your question? – Tugay İlik Jul 1 at 6:18
0
0

bst365体育投注网址大全Assuming you are using with , here's an example.

form
    input(type="checkbox" value="checked" name="checkbox" checked)
    input(type="radio" value="checked" name="radio" checked)
    input(type="submit", value="Submit")

bst365体育投注网址大全When this form submits, the express handler will receive the form data, an example handler:

    router.use(bodyParser().urlencoded({ extended: true }));
    router.post('/form',(req,res) => {
        //req.body: { checkbox: 'checked', radio: 'checked' }
        res.render('anotherPage', {radio: req.body.radio, checkbox: req.body.checkbox});
    })

Then in anotherPage.pug

form
    input(type="checkbox" value="checked" name="checkbox" checked=checkbox)
    input(type="radio" value="checked" name="radio" checked=radio)
    input(type="submit", value="Submit")

This way, the data can be passed on to the anotherPage.pug while maintaining the fields from the original page. You can also do this with other input types, such as text, by simply taking their value and passing it to the pug renderer.

| improve this answer | |

Your Answer

Rashid Al Barwani is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.