Handle button click as form submit.
npm i formless-button
In order to work properly, you have to add meta tag with CSRF token into <head>
<meta name="csrf-token" content="AAABBBCCCDDDEEE">
For Laravel:
<meta name="csrf-token" content="{{ csrf_token() }}">
In your JS file just import FormlessButton.js
, for example
import FormlessButton from "formless-button/FormlessButton";
FormlessButton will query <button>
with data-method
and data-url
attributes.
<button data-method="DELETE" data-url="https://example.com/user/44">Delete user</button>
Under the hood, FormlessButton will listen for click event, after that FormlessButton will create & submit basic <form>
with _token
and _method
inputs.