-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Validation messages not always showing #27729
Comments
what is your is issue You are facing Are You getting the Validation failure but no error message OR Validation success and data is being processed |
Can you reproduce this on a fresh installation of Laravel? |
ManojKiranA: I really don't understand your question... The validation succeeds, but sometimes the error messages doesn't contain anything. staudenmeir: Good question. Haven't tried that. Guess it could be worth testing. Btw, I have now also tried simply dd:ing $errors and when the error messages don't display, the errorbag is definitely empty. Also, forgot to mention in the original report, I've tried with a custom FormRequest as well, gives the exact same behaviour. |
try this create file named as and paste the following code into it
Now Open Your and incude that and you will get something please comment the result |
its not the solution think a situation if he has done many modules in project |
Ok, added that code. When the displaying of my own errors don't work that one doesn't either, but when my errors display I get the following:
I think this leads to the same conclusion as all other tests I've done: Sometimes there are no errors produced even though the validation fails. Since a short delay in the store function makes things work it must have something to do with the $errors array not being populated fast enough. Don't know enough about the inner workings to understand exactly what's happening though... |
Have You tried FormRequest |
Yep. Mentioned that above. Makes no difference. |
try the
|
Nope, that gives the same problem :-( |
do you have your app open in another tab that could be affecting your session? |
May not be the case here, but the answer usually resides in the code deemed "irrelevant". |
rs-sliske: Nope, only one tab open. devcircus: The code I deemed as irrelevant is never reached at all, since the validation fails. Verified that by a logger() call as the first row after the validation. |
@DanielMalmgren can you create an app with a minimum setup that re-creates the problem which we can test with? |
I'm facing the same issue. I even created two different fresh projects on 5.8 version but still facing the same problem with Validation customized message/rule or custom Request Class. No error, Not executing method after submit.
}` Model:
} |
@DanielMalmgren @guccilive are you both still experiencing this? |
Yep, the problem persists in 5.8.8. Haven't got any time for digging any deeper though, for now I'm just putting usleep() calls in the beginning of all my store functions. |
@DanielMalmgren - what session driver are you using? Can you try switching to a different session driver and trying again? |
@laurencei Sorry, forgot to mention here. I'm normally using file session drivers, but I've already tried changing to database, didn't make any differene. |
Is the form behind an auth page - i.e. do you need to be logged in to see it? The most common reason for failed validation messages is a session failure.
Homestead has Redis - try switching to a Redis session driver and see if it happens there? Both file + database are not true atomic storage. |
Also @staudenmeir asked this a while ago:
to which you replied
The default Laravel install with default auth gives you a good starting point. Create a basic form and see if you can reproduce there. If not, slowly add stuff back in until the problem arises... |
The entire site is behind SAML2 authentication (https://github.com/aacotroneo/laravel-saml2). I tried disabling authentication now though, going completely unauthenticated, and the problem persists.
Ok, tried redis too. Same problem.
Yep, I guess this is the next time to test. Too tight schedule currently though, guess this will need to hang in the air until I get time to test. |
Essentially it has to boil down to one of two things:
Either way, it's fairly safe to say this is not Laravel specific at this point in time. It's not reproducible for anyone else with the scenario you've given. The only thing I can think of is some strange environment setup that causes an edge case, in which situation that might be a Laravel bug. But until you can point it down one way or the other, there's not much we can do here. Once you track it down, ping us and we can reopen this with new information. |
I've just upgraded to laravel 5.8 from 5.7 and I've noticed the same issue. Validation works i.e user is redirected to the form page but no validation messages are showing. |
any solutions? i have same issue |
I never found any solution. There's obviously a bug here somewhere but I haven't succeeded in proving exactly where, so for the time being I'm living with usleep() calls the first thing in all my store, update and destroy methods. I don't know though if any devs are still reading here now that the ticket is closed? |
Like was mentioned already, the best way to track it down to a bug in your code or a hug in the framework is to create a new laravel app and only add the relevant code for showing the error messages. If the bug persists in a new app, push that app to github so the community can help. |
Same issue, v5.8.28, with redis:
|
I never found any solution. you had lucky? |
I solved this problem by changing xampp to mamp |
This might help. |
Moving \Illuminate\Session\Middleware\StartSession::class and \Illuminate\View\Middleware\ShareErrorsFromSession::class from web But I don't know if this can cause unexpected behavior on |
|
I having the exact same problem here! Laravel 9.28 on xampp 8.1.6 -> Win10. Did anyone found a solution? |
Found the bug, in livewire.php configfile, the Assets and App_url was wrong pointed. |
I've started a new Laravel project about 1 month ago and I am facing this problem too. Sometimes Laravel Validation works fine, but in others they simply go back to the form and does not show the errors. I test the same error many times, and it look like it only works properly whenever it wants. It's like it works fine and show the errors 2 or 3 times and then on the next test it shows just a list with no errors, even the validation working nice. I am reading a lot of forums about that but in no place I found the answer. The flash message are also the same way, sometime it works and sometimes don't. I don't know if it is my computer, or OS, or browser, Laravel version, extensions, or whatever... Using Chrome and Ubuntu 18.04 |
Jeez... This one was pretty hard to figure out. There are a lot of similar related issues what turns that very tricky. I think here is the right thread to share what I found. For instance, I'm working in a legacy system that was updated from Laravel 5.2 to 5.5 a few months ago, so keep in mind that your issue might be different. Initially I thought that it could be due the settings of the middlewares, more about that in the links below:
After a few hours without success or anything really helpful, I decided to dig the old code with Laravel 5.2. Well, they changed the behavior of // 5.5
public function validate(Request $request, array $rules,
array $messages = [], array $customAttributes = [])
{
$this->getValidationFactory()
->make($request->all(), $rules, $messages, $customAttributes)
->validate();
return $this->extractInputFromRules($request, $rules);
} // 5.2 - I didn't look carefully, but it seems that wasn't changed until 5.4
public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
{
$validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
} After figured out that, I went back to the docs and didn't find anything related to that. Anyway, it seems that after Alternatively,you can create a custom trait using the old code from After recover the trait from Despite of that, keep in mind this might cause other issues, if possible it's better to use |
Description:
I've got some kind of strange race condition here... I have got a form posting to Laravel. The function receiving the post currently looks like this:
The strange thing here is that if I remove the first line (the delay), my error messages only pops up in the browser sometimes, like one time in two (seemingly randomly distributed). Discovered this first by adding a debug log output, which obviously took enough time for things to work... The validation always works (ie the code after the validate() call don't get executed) but the user gets no notification about what's wrong.
Anyone seen this before?
This happened also in Laravel 5.7, just never got around to report it. Now on 5.8. Happens both on my dev machine (hyperv Homestead) and production machine (Ubuntu 18.04).
I don't know if it's relevant, but here's my code for displaying the errors:
The text was updated successfully, but these errors were encountered: