简体   繁体   English

Symfony验证嵌入集合

[英]Symfony validating embed collection

I have embed files collection, everything works fine except validations. 我已经嵌入了文件集合,除了验证之外,其他一切都正常。

If I'm uploading 3 files and 1 one of them don't pass validation requirements, then another 2 files also won't be uploaded or get, for example, their names saved in DB. 如果我要上传3个文件,而其中1个文件没有通过验证要求,则另外2个文件也不会被上传或获取,例如,文件名保存在数据库中。

Is there any solution to give that error message on 1 file, but save that another 2 files that are passing validations? 有什么解决方案可以在1个文件上显示该错误消息,但要保存另外2个通过验证的文件吗?

I don't think there is a solution for that. 我认为没有解决方案。 If there is an error, your form never get in the state "isValid", and I assume you don't save anything in database until your $form->isValid() is true. 如果有错误,您的表单永远不会进入“ isValid”状态,并且我假设您不会在$form->isValid()为真之前在数据库中保存任何内容。 You need to handle each file individually, or to add logic in your controller to save valid files, even if your whole form isn't valid (which is not a good Idea I think). 您需要单独处理每个文件,或者在控制器中添加逻辑以保存有效文件,即使您的整个表单无效(我认为这也不是一个好主意)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM