Reputation: 2550
I have a registration form and it was working until it just didn't. I am sure I did something with the code because I am new to laravel 4 so I am unable to identify my wrong doing. Now I am getting
This webpage has a redirect loop.
This is the route file:
Route::get('/','MainController@index');
Route::get('/login', 'MembersController@login');
Route::get('/signup', 'MembersController@signup');
/*handled by controller to register the user that signed up*/
Route::get('/register', 'MembersController@register');
/* Handle authenticating a user when loggin in*/
Route::post('register', array(
'uses' => 'MembersController@register',
'as' => 'members.register'
));
and this is the form opening:
@section('content')
{{ Form::open(array('route' => 'members.register')) }}
......
{{ Form::close() }}
@stop
and this is the validation where if there is an error, it used to redirect to the sign-up page again and show them (and it did until it broke)
public function register()
{
$rules = array(
# place-holder for validation rules
'firstname' => 'Required|Min:3|Max:40|Alpha',
'lastname' => 'Required|Min:3|Max:40|Alpha',
'email' => 'Required|Between:3,64|Email|Unique:users',
'country' => 'Required',
'password' =>'Required|AlphaNum|Between:7,15|Confirmed',
'password_confirmation'=>'Required|AlphaNum|Between:7,15'
);
/*Create new user if no user with entered email exists. Use validator to ensure all fields are completed*/
$user = new User;
$validator = $this->validate(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('register')->withErrors($validator);
}else{
echo "Success";
}
}
Thanks for the help :)
Upvotes: 1
Views: 796
Reputation: 12169
Change the following line
return Redirect::to('register')->withErrors($validator);
with this
return Redirect::back()->withInput()->withErrors($validator);
You are calling the route register infinite times.
Remove this route as well. You only need post route.
/*handled by controller to register the user that signed up*/
Route::get('/register', 'MembersController@register');
Upvotes: 3