saimcan
saimcan

Reputation: 1762

Laravel Validator always shows required error message

While testing, system always returning me required customized message. For example i want the validator to check if the passwords match. But error message shows me "Password Validation is required" instead of "Passwords does not match".

Here is my validation function and rules.

protected function getRegisterValidator()
{
    $message = array(
        'same' => ':attribute ve :other tekrarları birbirini tutmalı.',
        'between' => ':attribute en az :min en fazla :max karakterden oluşabilir.',
        'min' => ':attribute en az :min karakter içermelidir.',
        'max' => ':attribute maksimum :max karakterden oluşabilir.',
        'alpha_num' => 'girilen :attribute alfanumerik olmalıdır.',
        'unique' => 'Bu :attribute ile zaten önceden kayıt olunmuş.',
        'email' => ':attribute geçerli bir mail adresi değil.',
        'captcha' => 'Doğrulama karakterlerini yanlış girdiniz.',
        'required' => ':attribute alanı boş olamaz.'
    );
    return Validator::make(Input::all(),array(
        'Kurum' => 'required',
        'Ad' => 'required',
        'Soyad' => 'required',
        'Görev' => 'required',
        'Email' => 'required|email|unique:user',
        'Email Tekrarı'=> 'required|same:Email',
        'Şifre' => 'required|between:8,12',
        'Şifre Tekrarı' => 'required|same:Şifre',
        'Doğrulama' => 'captcha|required'
    ), $message);
}

Thanks in advance.

Upvotes: 2

Views: 1932

Answers (2)

saimcan
saimcan

Reputation: 1762

I found the solution. The space between field names like "Şifre Tekrarı" or "Email Tekrarı" leading an error and laravel validator cannot compare the values between "Şifre" and "Şifre Tekrarı" fields.

The solution is setting field names without spaces in your HTML file (or blade), and it does not involve anything with Turkish characters.

protected function getRegisterValidator()
{
    $message = array(
        'same' => ':attribute ve :other tekrarları birbirini tutmalı.',
        'between' => ':attribute en az :min en fazla :max karakterden oluşabilir.',
        'min' => ':attribute en az :min karakter içermelidir.',
        'max' => ':attribute maksimum :max karakterden oluşabilir.',
        'alpha_num' => 'girilen :attribute alfanumerik olmalıdır.',
        'unique' => 'Bu :attribute ile zaten önceden kayıt olunmuş.',
        'email' => ':attribute geçerli bir mail adresi değil.',
        'captcha' => 'Doğrulama karakterlerini yanlış girdiniz.',
        'required' => ':attribute alanı boş olamaz.'
    );
    return Validator::make(Input::all(),array(
        'Kurum' => 'required|min:3|max:60',
        'Ad' => 'required|min:3|max:30',
        'Soyad' => 'required|min:3|max:30',
        'Görev' => 'required|min:1|max:60',
        'Email' => 'required|email|unique:user|same:Email_Tekrarı',
        'Email_Tekrarı'=> 'required',
        'Şifre' => 'required|between:8,12|same:Şifre_Tekrarı',
        'Şifre_Tekrarı' => 'required',
        'Doğrulama' => 'captcha|required'
    ), $message);
}

Important note :

If you are showing error messages with these field names like "Email_Tekrarı" (i mean there is a _ character included) the error message ignores "_" character and shows error message as like "Email Tekrarı field is required".

Works smoothly.

Thank you for your patience.

Upvotes: 0

olgundutkan
olgundutkan

Reputation: 406

try this

$message = [
        'şifre.required' => 'Şifre alanı boş bırakılamaz',
        'şifre.same' => 'Şifre alanları eşleşmiyor',
    ];

"şifre" is input name.

Upvotes: 1

Related Questions