Hello there,
i am trying a really simple form validation, but somehow it does not work out.
here is my registration form:
<h1>Registration form</h1>
{{ Form::open(array('url' => 'registration')) }}
{{-- Username field. ------------------------}}
{{ Form::label('username', 'Username') }}
{{ Form::text('username') }}
{{-- Email address field. -------------------}}
{{ Form::label('email', 'Email address') }}
{{ Form::email('email') }}
{{-- Password field. ------------------------}}
{{ Form::label('password', 'Password') }}
{{ Form::password('password') }}
{{-- Password confirmation field. -----------}}
{{ Form::label('password_confirmation', 'Password confirmation') }}
{{ Form::password('password_confirmation') }}
{{-- Form submit button. --------------------}}
{{ Form::submit('Register') }}
{{ Form::close() }}
And thats my Route::post :
Route::post('/registration',function()
{
// Fetch all request data.
$data = Input::all();
$rules = array(
'username' => 'required|alpha_num|min:3|max:32',
'email' => 'required|email',
'password' => 'required|min:3|confirm',
'password_confirmation' => 'required|min:3'
);
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
//Something
return 'Data was saved';
}
return Redirect::to('/')->withErrors($validator);
});
It seems like the 'confirm' is the problem, whenever i dont comment it out i get:
Whoops, looks like something went wrong.
tried everything so far, would be really glad if someone could help me out here.
i am little bit of a noob in laravel to be honest ;)
thanks.
You have a small typo in your rules. It should be:
$rules = array(
'username' => 'required|alpha_num|min:3|max:32',
'email' => 'required|email',
'password' => 'required|min:3|confirmed',
'password_confirmation' => 'required|min:3'
);
Just for your knowledge, you don't really need to validate password_confirmation. If it must match password, then it must also have the same validation. :)
FYI, if your application is still in development, change 'debug' => false, to 'debug' => true, in your app/config.php so you can see the detailed information of the error and faster identity where is the error.
I have a similar problem with Password not working with confirmed. If I take |confirmed out of the password parameter it saves the user but allows a password of less than 6 characters. Can you let me know the correct syntax to have min:6 and confirmed working?
public static $rules = [
'username' => 'required',
'email' => 'required|unique:users|email',
'password' => 'min:6|required',
'password_confirmation' => 'min:6|same:pass'
];
surferway said:
I have a similar problem with Password not working with confirmed. If I take |confirmed out of the password parameter it saves the user but allows a password of less than 6 characters. Can you let me know the correct syntax to have min:6 and confirmed working?
public static $rules = [ 'username' => 'required', 'email' => 'required|unique:users|email', 'password' => 'min:6|required', 'password_confirmation' => 'min:6|same:pass' ];
'password' => 'required|min:6|confirmed
Solved password validation issue. Please try below method
public static $rules = [
'username' => 'required',
'email' => 'required|unique:users|email',
'password' => 'min:6|required',
'password_confirmation' => 'min:6|same:password'
];
You can match two form field using (same:field name) this method.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community