Form::file: How to repopulate with Input::old After Validation Errors and/or on Update?

…衆ロ難τιáo~ 提交于 2019-12-05 16:29:48
Needpoule

Apparently you can't. Browsers don't allow you to set a value on a file input for security reasons.

There are two silimar questions, not laravel related but i think answers could help you:

Can you re-populate file inputs after failed form submission with PHP or JavaScript?

Restoring the value of a input type=file after failed validation

Maybe your best shot would be to make the validation client-side (javascript/jquery).

Of course there has to be (ALWAYS) server-side validation. (remember javascript can be disabled on client-side).

But I believe that, this way 99.99% of the cases, the form submission will be successful!

Basically, when is indeed submit, it is already validated with sames rules as the servers, so it will not submit until it is not "as the server likes" :)

Cheers

For complex form submits I would recommend to use AJAX:

  1. You may do a first AJAX form send that does the server side validation.
  2. Then, if it's all fine you should launch via Javascript the form POST with file input.

I've answered a similar question for Laravel there but I hope it will be helpful for a general approach: Laravel 5.1: keep uploaded file as old input

Remove the redirect, your validation and input values should show on the same page, only redirect upon success.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!