0

this is pug form which is sending data to the requested url

   form.form.form-user-data(action='/submit-user-data' method='POST')
        .form__group
          label.form__label(for='name') Name
          input#name.form__input(type='text', value=`${user.name}`, required)
        .form__group.ma-bt-md
          label.form__label(for='email') Email
          input#email.form__input(type='email', value=`${user.email}`, required)
        .form__group.form__photo-upload
          img.form__user-photo(src=`img/${user.photo}`, alt='User photo')
          a.btn-text(href='') Choose new photo
        .form__group.right
          button.btn.btn--small.btn--green(type="submit") Save settings

and this is is route i have created for getting data from the body

router.post('/submit-user-data', (req, res) => {
     console.log(req.body);
     res.status(200).send();
});

when clicking submit i am not recieving body only {} i am receving

1
  • 2
    Did you instruct express to use express.json()?
    – pierpy
    Commented May 8 at 18:32

1 Answer 1

1

Browsers will submit values of <FORM> controls only if the control has a NAME attribute. ID alone won't do. So it should be, for example:

.form__group.ma-bt-md
   label.form__label(for='email') Email
   input#email.form__input(type='email', name='email' value=user.email, required)

Separately, you can assign Javascript expressions (limited to some operators) directly to Html element attributes. There is no need to use interpolated strings.

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