这是我的表单:
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($invite, 'email')->textInput([
'id' => 'register-email',
'placeholder' => Yii::t('UserModule.views_auth_login', 'email')]);
?>
<?php echo $form->field($invite, 'check')->checkbox([
'id' => 'check',
'uncheck' => null])->label(
Yii::t('UserModule.views_auth_login', 'I have read and accept') . ' <a href="#">'
. Yii::t('UserModule.views_auth_login', 'Terms & Conditions') . '</a> '
. Yii::t('UserModule.views_auth_login', 'and')
. ' <a href="#">' . Yii::t('UserModule.views_auth_login', 'Privacy Policy')
. '</a>' . '.');
?>
<hr>
<?php
echo \humhub\widgets\AjaxButton::widget([
'label' => Yii::t('UserModule.views_auth_login', 'Register'),
'ajaxOptions' => [
'type' => 'POST',
'beforeSend' => new yii\web\JsExpression('function(){ setModalLoader(); }'),
'success' => 'function(html){ $("#globalModal").html(html); }',
'url' => Url::to(['/user/auth/login']),
],
'htmlOptions' => [
'class' => 'btn btn-primary', 'id' => 'registerBtn'
]
]);
?>
<?php ActiveForm::end(); ?>
规则:
public function rules()
{
return [
[['email'], 'required'],
[['email'], 'unique'],
[['email'], 'email'],
[['email'], 'unique', 'targetClass' => \humhub\modules\user\models\User::className(), 'message' => Yii::t('UserModule.base', 'E-Mail is already in use! - Try forgot password.')],
[['check'], 'required'],
[['check'], 'compare', 'compareValue' => 1, 'message'=>'bla-bla-bla'],
];
}
如何使我的表单仅在'email'不为空且有效以及'check'被选中时才有效?现在的问题是'check'没有通过验证。谢谢。
'uncheck' => null
和compare
规则,看是否会有任何不同。 - Kostas Mitsarakis