Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
Last updated 2 years ago.
0

Adding this to the form still didn't post.

Last updated 2 years ago.
0

Please enable the debug mode in the config file and you can see what is going wrong.

Last updated 2 years ago.
0

This is what shows with debug on


Whoops, looks like something went wrong.
1/1 TokenMismatchException in VerifyCsrfToken.php line 46:

    in VerifyCsrfToken.php line 46
    at VerifyCsrfToken->handle(object(Request), object(Closure)) in compiled.php line 7620
    at Stack->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 10568
    at ShareErrorsFromSession->handle(object(Request), object(Closure)) in compiled.php line 7620
    at Stack->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 9340
    at StartSession->handle(object(Request), object(Closure)) in compiled.php line 7620
    at Stack->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 10277
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in compiled.php line 7620
    at Stack->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 10226
    at EncryptCookies->handle(object(Request), object(Closure)) in compiled.php line 7620
    at Stack->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in compiled.php line 7620
    at Stack->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in compiled.php line 7614
    at Stack->then(object(Closure)) in compiled.php line 1215
    at Kernel->handle(object(Request)) in Kernel.php line 32
    at Kernel->handle(object(Request)) in index.php line 53


No idea what to do to fix it. Just post not working get is working.

Last updated 2 years ago.
0

I think I got it working, please correct me if I am wrong. I gather that for a post, a token is now required in the form, is this correct? And I re-read the manual and copied and pasted there example:

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">

This worked with no errors. Your token was:

<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />

With 3 sets of curly braces. Hey thanks for pointing me in the right direction. I am still confused on the ne way to log users, hopfully I'll figure it out. At least I got posting to work. And thanks for the debug tip.

Last updated 2 years ago.
0

I had the same issue...dont really understand laravel 5 yet. It seems a bit more complicated to me; but i am not very smart...ha.

Last updated 2 years ago.
0

Someone here tried to do that as Ajax post without use form?

L5 use "csrf" by default, that's why cause the errors on the "verifyCsrfToken.php".

I just got it working removing the line:

'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken'

from /app/Http/Resquests/Kernel.php, of course I don't have csrf verifcation anymore, but I'd like to keep with.

Anybody knows what's the best way to handle that?

Thanks :)

Last updated 2 years ago.
0

If you use the standard Form::open()/Form::model() and Form::close() methods, the CSRF input should be created automatically in the HTML output. It certainly works like that in Laravel 4 - cannot see why they would take this out.

EDIT: cant seem to find a link in the Laravel dev docs for more information on forms, although they are accessible via here

Kindest Regards, Dave

Last updated 2 years ago.
0

Hi, I just got it working as Ajax Post.

Firstly I put back the line on /app/Http/Resquests/Kernel.php:

'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken'

and on my jquery ajax I did like that:

$_token = "{{ csrf_token() }}";
$.post( 'myurl', { param1: $param1, param2: $param2, _token: $_token })
.done(function( data )
{
     console.log('Done!');
});

Simple as this, no secrets :)

Last updated 2 years ago.
0

Thank you venanciorodrigo. You just saved my night.

0

The best way to solve this problem "X-CSRF-TOKEN" is to add the following code to your main layout, and continue making your ajax calls normally:

<meta name="csrf-token" content="{{ csrf_token() }}" />
<script type="text/javascript">
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
</script>

Reference.

Last updated 9 years ago.
0

above code didn't work for me, but i figure out new solutions which works for me in L5, instead of use ajaxSetup with headers just set input name _token and send it. here is my code example (but u must create form with form::open() to get in form

			  $(document).ready(function() {
				  $("#registerBitch").click(function(event){
					  $.post( 
						 "{!! URL::to('user/register') !!}",
						 { _token: $('#registerForm input[name=_token]').val() },
						 function(data) {
							console.log(data);
						 }
					  );
				  });
			   });

0

I was getting this message because my disk was out of space. df -H pointed this out but not until a lot of other debugging.

When the disk is full laravel can't save the updated csrf token but return it to the browser where it is then used.

0

I had this problem because the server was throwing a 500 error. Check your logs before running down the wrong path!

0

Mahmoudz said:

The best way to solve this problem "X-CSRF-TOKEN" is to add the following code to your main layout, and continue making your ajax calls normally:

<meta name="csrf-token" content="{{ csrf_token() }}" />
<script type="text/javascript">
   $.ajaxSetup({
       headers: {
           'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
       }
   });
</script>

Reference.

You just saved me hours of headache! Thank you!

Last updated 9 years ago.
0

Hello venanciorodrigo, your trick works great.

I got other solution on it, http://www.camroncade.com/disable-csrf-for-specific-routes-laravel-5/ worked on it. But again get next error

Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, boolean given, called in ...

:(

0

venanciorodrigo said:

Hi, I just got it working as Ajax Post.

Firstly I put back the line on /app/Http/Resquests/Kernel.php:

'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken'

and on my jquery ajax I did like that:

$_token = "{{ csrf_token() }}";
$.post( 'myurl', { param1: $param1, param2: $param2, _token: $_token })
.done(function( data )
{
    console.log('Done!');
});

Simple as this, no secrets :)

Nice~ THX

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jimgwhit jimgwhit Joined 13 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.