vrapan's avatar

LaravelCollective forms clearing after failed validation

As per title, have been working on this for quite a while, with my forms always being able to fill up with their values if validation failed. However now all of a sudden the form clears up when the validation fails and the message appears, if I refresh the page via the browser the fields get filled up again. GRRRRRR!!!! Thanks to everybody that can shed some light

BTW I am using laravel collective form::open and never had to use input old before...

0 likes
7 replies
renedekat's avatar

Could you please rephrase your question? It is unclear to me what the desired result should be given a certain scenario.

vrapan's avatar

When validation fails and I get redirected to the form the form is empty . ie it clears out all the fields that were filled.

vrapan's avatar

Even though I use laravelcollective forms? It is very strange because I have other forms that do not exhibit that behaviour and I could swear that up until a few days ago that was not an issue. Not sure I have done since then though.

vrapan's avatar

Ok I know but it is a simple standard form. So anyway I have found the problem but I am not sure how to solve it...

The issue is that the page contains multiple forms, so the request old input only includes the values of the form submitted but not of the rest. So I am making the assumption that this is the reason why the form is getting emptied.

the interesting thing - and why I did not discover that earlier - is that if I submit the very first form on the page nothing loses its values but if I submit subsequent ones they do - I even tried putting the first form further down the page to eliminate the possibility that the top form was somewhat different but it exhibited the same behaviour, ie the moment I submitted that form all the forms on the page lost their input.

milenaAz's avatar

I know it is a very old question but i had the same issue.. so here is what worked for me...

$rule = array(
            'agency' => 'required|max:50|unique:agencies,agency',
            'country' => 'max:30',
            'email' => 'sometimes|email',
            'telephone' => 'string',
            'fax' => 'string',
            'comments' => 'max:255',
            'address' => 'max:50'
        );

        $validator = Validator::make($request->all(), $rule);

        if($validator->fails()) {
             return redirect()->back()->withInput($request->all())->withErrors($validator);
        }

Please or to participate in this conversation.