How to redirect back to form with input - Laravel 5

后端 未结 9 1210
离开以前
离开以前 2020-12-01 02:53

How do I redirect back to my form page, with the given POST params, if my form action throws an exception?

9条回答
  •  不知归路
    2020-12-01 03:20

    In your HTML you have to use value = {{ old('') }}. Without using it, you can't get the value back because what session will store in their cache.

    Like for a name validation, this will be-

    
    

    Now, you can get the value after submitting it if there is error with redirect.

    return redirect()->back()->withInput();
    

    As @infomaniac says, you can also use the Input class directly,

    return Redirect::back()->withInput(Input::all());
    

    Add: If you only show the specific field, then use $request->only()

    return redirect()->back()->withInput($request->only('name'));
    

    Hope, it might work in all case, thanks.

提交回复
热议问题