16

if the validation fails it's not clear to me how i could pass the old input to fill again the form.

I mean, I know how to pass the data when using the Validator class and redirecting after fail with the method withInput(), but I'm trying to learn how to use Form Requests provided in laravel 5. Thanks

1

3 Answers 3

36
$username = Request::old('username');

or in view:

{{ old('username') }}

Read more: http://laravel.com/docs/5.0/requests#old-input

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

5 Comments

{{{ old('username') }}} // for laravel earlier versions xss preventing
I had to use the e() function in this case <input id=targa type=text name=targa size=10{!! (old('targa'))?' value="'.e(old('targa')).'"':' placeholder="Ej. AAA000"' !!}> do you have any other idea to do the same thing? I will have to do it almost for every field as i love to use placeholders
@Gabz if you're using L5 you don't need to follow Alupotha comment.
@Alupotha author mentioned L5 in question and in tag.
This does not seem to work for file uploads form - I cannot seem to populate the file upload section within a form - it just returns an empty array
8

You can redirect with old data like below with validation error

return redirect()->back()->withErrors($validator)->withInput();

1 Comment

i tried this, but not working for me, we just need to pas this in controller right if validation condition fails
0

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

you must also define withInput() for the http route when redirecting to a page for example

return back()->withInput();

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.