In my PhotosController, I am trying to modify the edit action so that it shows the existing value in the Form::file() input field (and, so that it repopulates the field if validation fails).
if ($validation->passes())
{
// saves the image on the FS and updates the db entry
}
return Redirect::route('photos.edit')
->withInput(Input::all())
->withErrors($validation)
->with('message', 'There were validation errors.');
The uploading process works fine, but when I view an existing record, or if validation fails upon creation, the Form::file doesn't show the value. I looked up the method in the api, and it only accepts the name and optional options arrays. Whereas, the other methods in the FormBuilder class allow us to set the value using Input::old().
I've tried passing in the following values to withInput, but they've been to no avail: * Input::all() * Input::old() * Input::except('photo_path') * Input::get('photo_path')
How can I update this so that if validation fails, or if a user views an existing record, the Form::file() method will show the existing value?
I'm sure that I'm overlooking something incredibly simple because I haven't found other threads of people asking this...
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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments