lewis4u
lewis4u

Reputation: 15057

Laravel error 405 (Method Not Allowed) on form submit

I have a modal with an empty action="" which I am updating with javascript like this

document.edit_matrix.action = '/matrix/' + id;

When I open the modal the changed action is there:

<form id="edit_matrix" name="edit_matrix" method="post" action="/matrix/3">

And then I click on submit and it tries to post on this current page.... It's simply an awful feeling :disappointed: What is wrong? What do I need to change to make this work? It tries to post to this:

POST https://global.test.loc/matrixes 405 (Method Not Allowed)

enter image description here

This is the DOM after attribute update


Update:

Now I tried to hardcode the action like this:

 <form id="edit_matrix" action="/matrix/2" name="edit_matrix" method="POST">

and when I click submit button, nothing happens.... it's just dead

OK, I fixed that one... the type of the button was just button and not submit, but it's still not working Tries to submit to original page.... action attribute doesn't change.


Update:

It works now... the button was inside the form partial and I just removed it out of the form partial to create and edit view and now it works.

Upvotes: 1

Views: 461

Answers (1)

Th&#233;otime
Th&#233;otime

Reputation: 17

use setAttribute("action", "/newValue")

Upvotes: 1

Related Questions