this form receives + - 400 records daily, very rarely when making a record this is automatically duplicated with a difference of 1 or 2 seconds.
NumsController.php
public function actionCreate()
{
    $model = new Nums();
    $model->scenario = Nums::SCENARIO_CREATE;
    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        try {
            if ($model->treatment == 3 && ($model->cc == null || $model->cc == '')) {
                if ($EmailTo = filter_var($model->idUser->email,FILTER_SANITIZE_EMAIL))
                Yii::$app->mailer->compose()
                    ->setFrom('xxxxxx')
                    ->setTo($EmailTo)
                    ->setCc(array('xxxxxx', 'xxxxxx', 'xxxxxx'))
                    ->setSubject("xxxxxx")
                    ->setTextBody('Plain Text content')
                    ->setHtmlBody(
                        "Email Text Example")
                    ->send();
            }elseif ($model->treatment == 3 && ($model->cc != null && $model->cc != '')){
                if ($EmailTo = filter_var($model->idUser->email,FILTER_SANITIZE_EMAIL))
                if($EmailCC = filter_var($model->cc,FILTER_SANITIZE_EMAIL))
                Yii::$app->mailer->compose()
                    ->setFrom('xxxxxx')
                    ->setTo($EmailTo)
                    ->setCc(array($EmailCC, 'xxxxxx', 'xxxxxx', 'xxxxxx'))
                    ->setSubject("xxxxxx")
                    ->setTextBody('Plain Text content')
                    ->setHtmlBody(
                        "Other Email Text Example")
                    ->send();
            }
            return $this->redirect(['create']);
        }catch(Swift_SwiftException $exception){
            Yii::$app->session->setFlash('warning', "Email not sent");
            return $this->redirect(['view', 'id' => $model->id]);
        }
    } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}
I know the code is confusing but will it be the code problem? Could be server problem? is that it happens a few times, in 400 it happens only 2 times.
i have one Conditional Validator like this
['id_user', 'required',
            'when' => function ($model) {
                return $model->treatment == '2' OR $model->treatment == '3';
            },
            'whenClient' => "function (attribute, value) {
                return $('#treatment').val() == '2' || $('#treatment').val() == '3';
            }",
            'on' => self::SCENARIO_CREATE
        ],
beforeValidate() in common\models\Nums.php
public function beforeValidate()
{
    if ($this->scenario == self::SCENARIO_CREATE){
        $this->a = Yii::$app->user->identity->id;
        $this->date = date('Y-m-d H:i:s');
    }else {
        $this->a = $this->a;
        $this->date = $this->date;
    }
    return parent::beforeValidate(); // TODO: Change the autogenerated stub
}

 Congrats both on fixing the bug and admitting this !
 Congrats both on fixing the bug and admitting this !