Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii2生成所需复选框不会';行不通_Php_Yii2 - Fatal编程技术网

Php Yii2生成所需复选框不会';行不通

Php Yii2生成所需复选框不会';行不通,php,yii2,Php,Yii2,这是我的表格: <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($invite, 'email')->textInput([ 'id' => 'register-email', 'placeholder' => Yii::t('UserModule.views_auth_login', 'email')]); ?> <?php echo $for

这是我的表格:

<?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(); ?>

只有当“电子邮件”不为空且“支票”已选中时,我如何使我的表格有效?现在的问题是“检查”无法验证。谢谢。

删除
比较
规则并更新所需规则,如下所示

[['check']、'required'、'requiredValue'=>1、'message'=>'bla-bla-bla']、

请尝试以下操作:

在模型中添加此方法:

public function validateCheckWithEmail($attribute, $params) 
{
    if (empty($this->check) && !empty($this->email) && $this->validateAttribute($this, 'email')) {
        $this->addError($attribute, $this->getAttributeLabel($attribute).' field cannon be empty.');
    }
}
在规则中添加:

[['check'], 'validateCheckWithEmail', 'skipOnEmpty' => false, 'skipOnError' => false],

删除
'uncheck'=>null
,然后比较
规则,看看是否有什么不同。嗨,Kostas,它也不起作用。这对我使用
yii2v~2.0.14
dektrium/Yii2用户“^0.9.14”
规则验证器很有效。
[['check'], 'validateCheckWithEmail', 'skipOnEmpty' => false, 'skipOnError' => false],