Why get Unable to verify your data submission error in Yii2?

There are various solutions to this problem, I guess understanding why it happened in the first place helps solve the problem.

  1. It is either caused by an invalid csrf token,user generated csrf token, expired csrf token, all these 'csrf' issues will arise when you have custom forms built not using the 'ActiveForm' class.

If CSRF is not the issue,

  1. Its other cause occurs when you try to upload multiple files and the web server cannot handle the load. Some properties to check on this to make sure you are on the right track is to claculate the size of files one is attempting to upload and check the web server's post_max_size and upload_max_filesize

If you are running linux, check php.ini file for inputs like these:

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data    reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 8M

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M

Based on your calculations, adjust the above php.ini parameters to suite your needs, then test. I had a similar problem and I solved it.


Add this in the head section of your layout: <?= Html::csrfMetaTags() ?>


If you create the form manually (i.e. without using the yii form methods), you should add an input field like this:

<input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" />

source: http://zero-exception.blogspot.com/2015/01/yii2-using-csrf-token.html

Tags:

Yii2