A
A
Alex Black2016-07-22 01:21:08
Laravel
Alex Black, 2016-07-22 01:21:08

Laravel: _token value disappears after form submission. How to fix?

Good afternoon, dear developers. I would never post a question. Especially since he seems stupid to me. But I have already rummaged through the entire Toaster and the entire Internet.
Framework - laravel
The situation is as follows:
1. There is a form at post/add . It generates a hidden _token (using the Form:: facade or using the csrf_field() function - it doesn't matter) It looks like this:

<input name="_token" type="hidden" value="здесь токен">

2. The form is sent to the server (not Ajax, a simple PUT request)
3. The data is saved in the database and redirected to the same page. For example:
return redirect('post/add');
4. Everything is going well. But after going to the page, the form is generated without the value of the _token field. Like this: That is
<input name="_token" type="hidden">
, this form cannot be sent a second time. Before that, you need to go to the page again using the GET method.
Question: what am I doing wrong? How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Black, 2016-07-22
@s37dap42x

Yeah, the following was discovered by typing:
before making a redirect in the handler
There is such a code:
So, if you comment it out, then everything starts working. It turns out that this function somehow overlaps the token?
Can't delete my own question because I answered it myself.
The issue has been resolved. Apparently, working 18 hours in a row is harmful. Need to go to sleep. It turned out that there was a "flush" of all the values ​​​​before the form was displayed, so the token was not displayed.
Removed this piece of code and it all worked!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question