This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

majid.mehrafza27776
majid.mehrafza27776

Hi Guys,

I want to extend the User Plugin by adding custom fields and therfore custom validation rules and messages aswell. I've googled a lot on how to get my custom validation messages working and it finally did, but I've noticed that the custom messages for attributes like 'email' and 'password' are not changed and October still returns the standard :attribute phrase 'The email field is required.' although I've specified new messages for all the rules of 'email' and 'password. I think that I have to somehow dump or override the old rules but I cant figure how. Of course I added extendUserModel() to boot(). Some of my messages show, but email and password don't. This is how my extension of the User model looks like:

protected function extendUserModel(){

  UserModel::extend(function($model) {
      $model->addFillable([
          'tos',
          'privacy',
          'gender',
          'street',
          'street_nr',
          'adr_ext',
          'zipcode',
          'city',
          'country',
          'phone',
          'mobile'
      ]);

      $model->bindEvent('model.beforeValidate', function() use ($model) {
        $model->rules = [
          'name' => 'required|between:2,40',
          'surname' => 'required|between:2,40',
          'tos' => 'required|accepted',
          'privacy' => 'required|accepted'
        ];

        $model->customMessages = [
            'name.required'     => 'Bitte gib Deinen Vornamen ein!',
            'name.between'      => 'Der Name muss mindestens :min und maximal :max Zeichen lang sein!',
            'surname.required' => 'Bitte gib deinen Nachnamen ein!',
            'surname.between'  => 'Der Nachname muss mindestens :min und maximal :max Zeichen lang sein!',
            'tos.required'      => 'Um sich registrieren zu können, musst Du die Geschäftsbedingungen akzeptieren!',
            'privacy.required'  => 'Um sich registrieren zu können, musst Du die Datenschutzerklärung akzeptieren!',
            'email.required'    => 'Bitte gib eine Email-Adresse an!',
            'email.email'       => 'Bitte gib eine gültige Email-Adresse an!',
            'email.unique'      => 'Diese Email-Adresse ist bereits vergeben!',
            'password.required' => 'Bitte gib ein Passwort für dein Konto ein!',
            'password.between'  => 'Das Passwort sollte mindestens 4 Zeichen lang sein!'
        ];
      });
});
}

I found a lot of questions regarding the extension of $customMessages, but neither the threads, nor the documentary provide any solutions. I'm grateful for any help :)

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.