eidellev / inertiajs-adonisjs

279 stars 17 forks source link

Form data ends up in the url #34

Closed kevin-DL closed 3 years ago

kevin-DL commented 3 years ago

Hello, i am trying to do a form submission but when i a submit the form and get the response, the url changes to include the posted data into the url. Am i submitting/handling the form wrong?

The form submission

submit(form) {
      form
        .transform((data) => ({
          ...data,
          location: data.location.id ?? null,
          sport: data.sport.id ?? null,
        }))
        .post('/games/new', {
          onSuccess: () => {
            this.$toast.success('Game created.', {
              // optional options Object
            })
          },
        })
    }

The response from the handler for POST /games/new

return inertia.render('games/New', {
        sports,
        game: game.id,
      })

Thank you for your help

eidellev commented 3 years ago

Hey @kevin-DL ! Thanks for reporting this issue. I suspect that you're triggering the browser's default form handling mechanism instead of your own. You might be missing <form @submit.prevent="submit"> to suppress the browser's default behavior. The official Inertia documentation for forms might help you with figuring out what went wrong: https://inertiajs.com/forms

Let me know if it helped 😄

kevin-DL commented 3 years ago

@eidellev .Thank you for your response. The @submit.prevent is there. Now that i look at it the response from the form submission looks like this, do you think that's the reason

{"component":"games/New","props":{"auth":{"loggedIn":true,"user":{"id":1,"email":"xxxx@xxx.com","name":xxxxx","picture":"https://ssssss","remember_me_token":"xxxx","created_at":"2021-08-15T12:39:05.998+01:00","updated_at":"2021-08-16T20:13:01.078+01:00"}},"key":"xxxxxxx","sports":[{"id":1,"name":"Football"}],"game":36},"url":"/games/new?title=sdsdsfsdfsd&date=2021-08-22&time=10%3A58"}

The url field has the form values but the request is a post. I might change the way i do things but i wonder if there is something weird happening.

kevin-DL commented 3 years ago

If i return

inertia.redirectBack()

Then the issue does not happen. It happens only if i call inertia.render

eidellev commented 3 years ago

Thanks again for reporting this issue. It's been fixed in v4.1.1: https://github.com/eidellev/inertiajs-adonisjs/releases/tag/v4.1.1

Let me know if you run into any additional issues after you upgrade.

kevin-DL commented 3 years ago

Thank you