検証の比較は奇妙な動作です。何があっても、電子メールは決して同じではなく、常にエラーが表示されます。
これは検証用のコードです。
public function rules()
{
return [
[['first_name', 'last_name', 'email', 'conf_email'], 'required'],
['title', 'match', 'pattern' => '/^[a-zA-Z]{0,100}$/',
'message' => 'Title must contain only letters.'],
[['first_name', 'last_name'], 'match', 'pattern' => '/^[a-zA-Z]{0,45}$/',
'message' => 'The {attribute} must contain only letters.'],
[['email', 'first_name', 'last_name'], 'trim'],
[['email', 'conf_email'], 'email'],
['email', 'string', 'max' => 255],
['email', 'UniqueValidator'],
['conf_email', 'compare', 'compareAttribute'=>'email', 'skipOnEmpty' => false,
'message' => 'Emails do not match.'],
];
}
フォームのコード:
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
$form = ActiveForm::begin([
'action' => Url::toRoute([
'team/ajax-add-team-member',
'id' => $team->idteam,
'portalID' => $portal->idportal
]),
'enableAjaxValidation' => true,
'validationUrl' => '/team/team-validation',
'id' => 'team-invite-form',
'options' => [
'class' => 'clearfix'
]
]) ?>
<div class="col-md-12">
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-12">
<?php echo $form->field($model, 'title')->textInput() ?>
</div>
<div class="col-md-5 col-sm-5 col-xs-12">
<?php echo $form->field($model, 'first_name')->textInput() ?>
</div>
<div class="col-md-5 col-sm-5 col-xs-12">
<?php echo $form->field($model, 'last_name')->textInput() ?>
</div>
</div>
</div>
<div class="col-md-12">
<?php
echo $form->field($model, 'email')->textInput();
echo $form->field($model, 'conf_email')->textInput();
echo $form->field($model, 'is_medical_professional')->checkbox();
?>
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<?php
echo Html::submitButton('Send', ['id' => 'add-team-member-form-btn', 'class' => 'btn btn-default']);
ActiveForm::end();
?>
ここで何が起こっているoO?