AjaxValidation of 2 Inputs

Hi Guys,

I’m not getting any further, so please help me out :)

In my registration are 2 inputs fields "phone" and "mobile", the user needs to fill in one of those.

I created a custom validation rule as seen below, which works fine.


public function phone_or_mobile($attribute, $params) {

        $userProfile = new \app\models\UserProfile;

        if (empty($this->$attribute) && empty($this->{$params['second']})) {

            $this->addError($attribute, $userProfile->getAttributeLabel('phone') . ' oder ' . $userProfile->getAttributeLabel('mobile') . 'eingeben.');

        }

    }

The issue I currently have, is when the user is entering no phone but the field is validated, the error is created, all good, but when he is entering a mobile, the error on the phone field is still there, theoretically it should be fixed by calling the validation an the “second” attribute after the first is validated, but I can’t get it to work.

I would check if both of them are empty throw an error




        if (empty($this->phone)) && empty($this->mobile))

        {

                $this->addError('phone_or_mobile', 'phone or mobile should be filled');

        }