I am try to use unique validator for email in my model, but it doesn't work.. i mean no notification that display in form when user input the same email that already saved in db and user still can click submit button(and page reloaded) eventhough data isn't saved in db. What's wrong with my code?
this is my model validation:
['email', 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'string', 'max' => 255],
['email', 'unique', 'targetClass' => '\application\common\models\User', 'message' => 'This email address has been taken.'],
this is my form :
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
<?= $form->field($model,'email')->textInput()->input('email', ['placeholder' => "Email"])->label(false) ?>
...
<div class="form-group">
<?= Html::submitButton('SIGN UP NOW', ['class' => 'btn btn-sign', 'type' => 'submit']) ?>
</div>
<?php ActiveForm::end(); ?>
and this is my model to process save:
if (!$this->validate()) {
return null;
}
$user = new User();
$user->email = $this->email;
...
you should add a filter in your model validation.