beforeValidate code and create form does not work anymore

Hello,

I want to give a default value to name field when form is validated :


public function beforeValidate($insert)

    {

		if (parent::beforeValidate()) {

			$lookfor = Mappingtable::findOne(['id' => $this->mappingtable_id]);

			$this->name = $lookfor.'->'.$this->fieldname;


			return true;

		}

        return false;

    }

But when I create a record (crud generated views & controller) I click on create nothing happens

Sorry - I found my error

need to use $lookfor->fieldname

Don`t use beforeValidate. Create validator for this purpose




// rules()

['name', function($attribute) {

    $lookfor = Mappingtable::find()->asArray()->select(['id'])->where(['id' => $this->mappingtable_id])->one();

    if(lookfor) {

        $this->$attribute = $lookfor['your_field'] . '->' . $this->fieldname;

    }

}]