0

I have one controller and one Form Request Validation class: app\Http\Controllers\GuestController.php and app\Http\Requests\ItemValidation.php. In GuestController.php I use storeItem(ItemValidation $request) method to store item data which comes from <form> .

And in ItemValidation.php request class I redirect back to the form with following method if validation fails.

public function response(array $errors){
        return Redirect::back()->withErrors($errors)->withInput()->with('type', '2');
}

The main thing I want is to pass value from <form> (which is entered by user in form) to response method. I tried with following but it did not work:

public function response(array $errors, Request $request){
            return Redirect::back()->withErrors($errors)->withInput()->with('type', '2')->with('sub_menu_id',$request->sub_menu_id);
    }
2
  • did you alter (add) routes Route::get("/response", "GuestController@response"), pointing to controller? And pass form via post or get to that url? Commented Oct 5, 2016 at 11:20
  • Sorry, you did not get my question. Commented Oct 5, 2016 at 11:24

1 Answer 1

1

->withInput() flashes the previous input to the session.

In your form view, you should use the old() helper to repopulate the value if a previous input exists.

Blade:

<input type="text" name="username" value="{{ old('username') }}">

Plain PHP:

<input type="text" name="username" value="<?= e(old('username')) ?>">

If there is no previous input, it returns null, which echoes as an empty string.


Documentation: https://laravel.com/docs/5.3/requests#old-input

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.