0

I have a code that add new events created by the customer to the database, everything was working well until I added the image Upload fearture

What I did exactly is this :

1- I added enctype="multipart/form-data" to the form like below

<form class="form-group label-floating is-select" action="/envoi/event" method="POST" enctype="multipart/form-data">

2- inside that form I got this input <input name="datetimepicker" value="dd/mm/yyyy" id="datetimepicker"

3- in server side Node I got this

const dateNew = moment(req.body.datetimepicker, 'DD/MM/YYYY')
    console.log(req.body.datetimepicker)
    console.log(dateNew)

The output of both console.log are below

undefined
Moment<Invalid date>

both datetimepicker and enctype="multipart/form-data" are like this

<form class="form-group label-floating is-select" action="/envoi/event" 
      method="POST" enctype="multipart/form-data">
    <div class="form-group date-time-picker label-floating">
    <label class="control-label">Event Date</label>
    <input name="datetimepicker" value="dd/mm/yyyy" id="datetimepicker">
    </div>
    </form>

What I noticed that If I delete this enctype="multipart/form-data" everything works perfectly and I get as result the right value

Anyone faced this kind of problems ? or maybe I did something wrong

Best Regards,

Nodegeek
  • 280
  • 2
  • 18
  • 1
    will it help? https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data – falinsky May 22 '20 at 21:18
  • @falinsky when I used `application/x-www-form-urlencoded` the value date is now correct but the image upload is not working and if I replace it to `multipart/form-data` => the inverse is happening upload is working but date is undefined – Nodegeek May 22 '20 at 21:27
  • @falinsky I made some modification and it is working , could it possible to post your comment as answer ? to accept and vote u ? – Nodegeek May 22 '20 at 21:59
  • it would be better if you create a detailed answer on your own question with what you did. You will be able to accept it later. This way this question and answer will have more value for the community. – falinsky May 22 '20 at 22:01

0 Answers0