-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Validation error message is empty on array of file #12118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting. Ping @taylorotwell. |
same here, actually anything other than required wont trigger any error, same as on old 4.2 |
I have more information. if the file validation trigerred, the 'old' field form data will be gone too. So if I input 'name' and got wrong validation on the file, the field name will not be filled the next redirect. |
@lino10 i believe thats because the image validation bug doesn't treat this as a validation error rather its more of just redirect back. |
@lino10 here is a solution i used back in 4.2, give it a try and see if u have any success
|
@ctf0 Hi, I use the Form Request Validation method, how to implement your code using it? |
@lino10 ah yes, unfortunately that method doesn't give much of choice to customize the pipeline as u want however u can make the validation along with the rules in another class and inject it into ur store method and work on it as usual. EDIT: |
I am not able to recreate this issue. Form request validation on an array of files seems to work fine for me on a clean install of Laravel 5.2.12. Has this been fixed already? Maybe something else is going on? |
@kkiernan do u get an actual error message (anything other than |
@ctf0 Yes I get all error messages as expected. For example, if I upload a gif for the first image, this is the message bag I receive:
|
@kkiernan , Ping @GrahamCampbell right now am on 5.2.14 and i have the rules as
|
I just tested using the fresh 5.2.14, there's still no error messages. So why is this issue closed? Here's the app and resources folder, you just need to replace them to test. Just empty the name field and upload image other than gif. Tested using xampp and homestead |
I think I know why the error displayed for kkiernan. If you don't use enctype="multipart/form-data" on the form, the error will display. |
@lino10 No, my form does have the enctype set. |
@lino10 I just downloaded your files and they work fine for me. Hmm. |
@lino10 @ctf0 Ok, I am able to recreate this issue now. I had to create a new Homestead VM, and on that box I see the same thing you guys see. Weird. The |
am having this issue through |
@ctf0 The MessageBag seems ok all the way through the failedValidation method of the Illuminate\Foundation\Http\FormRequest class. Below is the error that is logged. Do you get a similar error in your storage/logs directory?
Update |
Potrential fix: Try replacing the
Update |
@kkiernan good find, let me test and come back to u asap. |
@kkiernan Wow! That fix is working! The 'old' data is also returned successfully! Regarding your comment above I don't know if this help or not, I'm using windows 10 64 bit and tested using xampp 3.2.2, also with homestead but not using artisan serve(serving website by editing yaml file) |
@lino10 Nice! It's odd that it happens on homestead but not my host machine. I am also on Windows 10 64-bit. I just noticed adding that return statements breaks other arrays, for example, an array of text inputs. The old data for those inputs wont be added to the session. We'd need to add a bit more logic to the withInput statement. |
@kkiernan sorry to tell u that nothing changed here, still getting the same old required msg. also i found another bug which if i uploaded a big file like a |
@GrahamCampbell @taylorotwell @kkiernan
I'm not expert of laravel framework, just a suggestion |
@kkiernan right now am downloading the vm to see if this is related to my machine or not, about the logging is there something like the |
@ctf0 Can you take a look in storage/logs and see if anything has been logged? |
@kkiernan sorry for the long delay, let me do some tests and will come back to u with the results |
@ctf0 No problem. It's such a weird bug. I took another look with fresh eyes and the existing Laravel code seems like it should work totally fine. Really odd. |
@kkiernan believe it or not actually this bug is there since 4.2 😢 |
@kkiernan @ctf0 So here's to reproduce:
So my conclusion is, something in php 7.0 break the validation logic |
@kkiernan
|
@lino10 @kkiernan $validate = Validator::make($request->all(), ['photo.*'=> 'required|image|max:2048']);
$photos = $request->file('photo');
// to make sure that we have at least one file in the photo array
if ($photos[0] != null) {
$validate->after(function ($validate) use ($photos) {
foreach ($photos as $photo) {
if ($photo->getError() != 0) {
$validate->errors()->add('photo_err', $photo->getErrorMessage());
}
}
});
}
if ($validate->fails()) {
return back()
->withInput()
->withErrors($validate);
} now keep in mind 2 things
|
Validator works fine for strings and other stuff, but not for files. |
@loursbourg validation works fine for single file, the issue is when u try to validate an array |
Was this issue fixed? Im still having this problem |
@KayTokyo open a new issue as this is closed and no one will look into it. |
Hi, after doing some testing, I think this is a bug.
I have this html
Form Request's rules
When the file type is not jpeg, it redirects back to the input page. So the validation works, but there's no error message. When I checked the error message bag, it is empty.
I'm using Laravel Framework version 5.2.12
Might be related: #6028
The text was updated successfully, but these errors were encountered: