【发布时间】:2013-05-02 11:40:14
【问题描述】:
我在使用令牌和文件字段表单时遇到问题。
表单的验证是这样的:
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection(array(
'fields' => array(
'file' => new File(
array(
'maxSize' => '2M',
'mimeTypes' => array(
'application/pdf', 'application/x-pdf',
'image/png', 'image/jpg', 'image/jpeg', 'image/gif',
),
)
),
)
));
return array(
'validation_constraint' => $collectionConstraint
}
当我上传一个无效大小的文件(~5MB)时,我收到了这个错误,这是我希望的:
The file is too large. Allowed maximum size is 2M bytes
但是当我上传一个太大的文件(~30MB)时,错误发生了变化:
The CSRF token is invalid. Please try to resubmit the form
The uploaded file was too large. Please try to upload a smaller file
问题是错误标记。我的表单中有 {{ form_rest(form) }} 代码。我认为错误更改是因为:How to increase the upload limit for files on a Symfony 2 form?
我不想增加上传限制。我希望不显示令牌错误。
【问题讨论】:
-
你有什么收获吗?
-
我没有找到解决方案。我在 getDefaultOptions 中将 csrf_portection 设置为 false,但这是为了避免错误消息。如果您找到解决方案,请联系我。
标签: symfony symfony-forms