Reputation: 889
Here is my Form
{{ Form::open(array('url' => 'register', 'class' => 'form-signin')) }}
// form username , password .. fields here
{{ Form::close() }}
And the route is
Route::post('register', 'RegisterController@registeruser');
And the Controller is
public function registeruser()
{
//validation
return Redirect::to('/')->withErrors($validator); // main
}
As, i am being redirected i won't be having any fields that is filled in the form.
I know that i should use request and response for this.
I tried with below response, even this is a horrible try.
return Response::view('home')->header('utf-8', $messages);
But while doing above even the page reloads and the values filled in the form disappears. How can i through the errors without the values disappears ?
Is there a way to have filled the fields in the form as entered ?
Upvotes: 1
Views: 545
Reputation: 7618
Let's suppose you have a validation like this:
$validation = Validator::make($input, $rules);
Then you need to do that:
if( $validation->fails() )
{
return Redirect::back()->withInput()->withErrors($validator->messages());
}
note the Redirect::back()
that allows you to get back to your form and fill it automatically with user input
Upvotes: 1
Reputation: 178
You can use Input::flash()
public function registeruser()
{
//validation
Input::flash();
return Redirect::to('/')->withErrors($validator); // main
}
Then in the controller method that handles the redirect you can access the old input with Input::old(). Using Input::all() will only return data for the current request.
You can also use the ->withInput() chained method on your return line.
Read more about it here http://laravel.com/docs/4.2/requests
Upvotes: 1
Reputation: 60048
You need to use ->withInput()
return Redirect::to('/')->withInput()->withErrors($validator); // main
Upvotes: 2