Brad Ahrens
Brad Ahrens

Reputation: 5178

Submit Laravel Form within Bootstrap Modal - CSRF Token

I'm creating a form inside of a bootstrap modal. Here is the form:

<form action="{{ url('/post')}}" method="POST" id="my_form">
  {{ csrf_field() }}
  <input type="text" name="Comments" id="Comments">
  <button onclick="form_submit()">Submit</button>
</form>

and here is the javascript I'm using to post it:

<script type="text/javascript">
function form_submit() {
  document.getElementById("my_form").submit();
 }
</script>

Unfortunately, when I submit, I get the following error:

(1/1) TokenMismatchException in VerifyCsrfToken.php (line 68)

I've also tried to insert a hidden field for the token:

<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />

Unfortunately, no luck.

Any idea how I can fix this?

Thanks!

Upvotes: 1

Views: 1940

Answers (1)

vdeshan
vdeshan

Reputation: 153

Insert this somewhere in ur header

 <meta name="c-token" content="{!! csrf_token() !!}" />

Upvotes: 1

Related Questions