E
E
EVOSandru62015-08-28 13:57:08
Yii
EVOSandru6, 2015-08-28 13:57:08

Why might not work in Yii enableClientValidation if $form->errorSummary and all $form->errors are set?

Good afternoon,
There is a registration form for the user. In its Users
model , there is an additional. fields not from the model that are processed in afterSave() Here is the form:

<?php
$form = $this->beginWidget('CActiveForm',
    [
        'id' => 'reg-form',
        'enableClientValidation' => true,
        'enableAjaxValidation' =>true,
        'clientOptions' =>
        [
            'validateOnSubmit' => true,
        ],
        'htmlOptions' =>
        [
            'class' => 'form',
            'style' => 'padding:10px;'
        ],
        'action' => ['users/'.Yii::app()->controller->action->getId()], // когда форма показывается и в других контроллерах, не только 'site', то я в каждый из этих контроллеров вставил actionQuick, a здесь указал — array('quick'); почему-то не получается с array('//site/quick')
    ]);?>
    <?php echo $form->errorSummary($model); ?>
                <?php echo $form->labelEx($model, 'name'); ?>
                <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 100)); ?>
                <?php echo $form->error($model, 'name'); ?>
                <?php echo $form->hiddenField($model, 'role_id', ['value' => $role->id]); ?>
                <?php echo $form->error($model, 'role_id'); ?>
                <?php echo $form->labelEx($model, 'email'); ?>
                <?php echo $form->textField($model, 'email', array('size' => 60, 'maxlength' => 100)); ?>
                <?php echo $form->error($model, 'email'); ?>
                <?php echo $form->labelEx($model, 'password'); ?>
                <?php echo $form->passwordField($model, 'password', array('size' => 32, 'maxlength' => 32)); ?>
                <?php echo $form->error($model, 'password'); ?>
                <?php echo $form->labelEx($model, 'verifyPassword'); ?>
                <?php echo $form->passwordField($model, 'verifyPassword', array('size' => 32, 'maxlength' => 32)); ?>
                <?php echo $form->error($model, 'verifyPassword'); ?>
                <?php echo $form->labelEx($model, 'telephone'); ?>
                <?php
                $this->widget('CMaskedTextField', array(
                    'model' => $model,
                    'attribute' => 'telephone',
                    'mask' => '+7-999-999-9999',
                    'placeholder' => '*',
                    'completed' => 'function(){console.log("ok");}',
                ));
                ?>
                <?php echo $form->error($model, 'telephone'); ?>
            </td>
        </tr>
                <?php
                $this->widget('zii.widgets.jui.CJuiAutoComplete',
                    [
                        'name'=>'placeName',
                        'value'=>'',
                        'source'=>Yii::app()->createUrl('cabinet/places/autocomplete'),
                        'options'=>
                        [
                            'showAnim'=>'fold',
                            'minLength'=>'3',
                            'select'=>'js:function( event, ui )
                            {
                                    $("#place_id_search").val( ui.item.id );
                                    $("#place_id").val( ui.item.id );
                                    return false;
                              }',
                        ],
                        'htmlOptions'=>
                        [
                            'onfocus' => 'js: this.value = null; $("#placeStart").val(null); $("#selectedvalue").val(null);',
                            'class' => 'input-xxlarge search-query',
                            'name' => 'Bids[placeStart]',
                            'placeholder' => "Введите первые 4 и более буквы региона",
                        ],
                    ]);
                ?>
                <?php echo $form->hiddenField($model,'place_id',['id'=>'place_id']); ?>
                <?php echo $form->error($model,'place_id'); ?>
        <?php if ($role->id == Users::ID_DRIVER): ?>
                    <?php
                    echo $form->checkBoxList($model, 'placesArray',
                        CHtml::listData($places, 'id', 'name'),['class'=>'places']);?>

                    <?php echo $form->error($model,'placesArray'); ?>

      
                    <header><span class="badge">Интересующие Вас перевозки</span></header>
                    <?php
                    echo $form->checkBoxList($model, 'categoryCargoArray',
                        CHtml::listData($categoryCargo, 'id', 'name'),['class'=>'categoryCargo']);?>
                    <?php echo $form->error($model, 'categoryCargoArray'); ?>
                    <?php
                    <header><span class="badge">Меня интересует информация:</span></header>
                    <?php
                    echo $form->checkBoxList($model, 'transportationsArray',
                        CHtml::listData($transportations, 'id', 'name'));?>
                    <?php echo $form->error($model, 'transportationsArray'); ?>
        <?php endif; ?>
    <?php if ($role->id == Users::ID_DRIVER):?>
        <div id="demo" class="collapse"><!-- in -->
            <table class="table table-crud">
                        <?php echo $form->dropDownList($model, 'carCategory', CHtml::listData($categoryCars, 'id', 'name'),
                            [
                                'emptyName' => 'Категория автомобиля',
                            ]); ?>
                        <?php echo $form->error($model, 'carCategory'); ?>
                        <?php
                        $this->widget('zii.widgets.jui.CJuiAutoComplete',
                            [
                                'name'=>'placeName',
                                'value'=>'',
                                'source'=>Yii::app()->createUrl('brands/autocomplete'),
                                'options'=>
                                [
                                    'showAnim'=>'fold',
                                    'minLength'=>'3',
                                    'select'=>'js:function( event, ui )
                                    {
                                        $("#BrandSearch").val( ui.item.value );
                                        $("#carBrands").val( ui.item.id );
                                        return false;
                                    }',
                                ],
                                'htmlOptions'=>
                                [
                                    'onfocus' => 'js: this.value = null; $("#carBrand").val(null); $("#selectedvalue").val(null);',
                                    'class' => 'input-xxlarge search-query',
                                    'name' => 'Users[carBrand]',
                                    'placeholder' => "Введите первые 3 и более буквы марки",
                                    'id'=>'BrandSearch',
                                ],
                            ]);?>
                        <?php echo $form->hiddenField($model,'carBrands',['id'=>'carBrands']); ?>
                        <?php echo $form->error($model, 'carBrands'); ?>
                        <?php echo $form->textField($model, 'carName', array('size' => 60, 'maxlength' => 100, 'placeholder' => 'Например: Газель')); ?>
                        <?php echo $form->error($model, 'carName'); ?>
                        <?php echo $form->textField($model, 'carSerialNumber', ['size' => 60, 'maxlength' => 100, 'placeholder' => 'Например: A 999 WMO']); ?>
                        <?php echo $form->error($model, 'carSerialNumber'); ?>
                        <?php echo $form->numberField($model, 'carVolume', ['min' => 0, 'placeholder' => 'м(3)']); ?> &nbsp;&nbsp;<span class="badge">м(3)</span>
                        <?php echo $form->error($model, 'carVolume'); ?>
                        <?php echo $form->numberField($model, 'carX', ['min' => 0, 'placeholder' => 'X м']); ?> &nbsp;&nbsp; <span class="badge">м</span> &nbsp;&nbsp;
                        <?php echo $form->numberField($model, 'carY', ['min' => 0, 'placeholder' => 'Y м']); ?> &nbsp;&nbsp; <span class="badge">м</span> &nbsp;&nbsp;
                        <?php echo $form->numberField($model, 'carZ', ['min' => 0, 'placeholder' => 'Z м']); ?> &nbsp;&nbsp; <span class="badge">м</span> &nbsp;&nbsp;
                        <?php echo $form->error($model, 'carX'); ?>
                        <?php echo $form->error($model, 'carY'); ?>
                        <?php echo $form->error($model, 'carZ'); ?>
                        <?php echo $form->error($model, 'carCorpus');?>
                        <?php echo $form->dropDownList($model, 'carCapacity', CHtml::listData($capacity, 'id', 'name')); ?>
                        <?php echo $form->error($model, 'carCapacity'); ?>
    <?php endif; ?>
            <td class="table-captcha">
                <?php
                if (CCaptcha::checkRequirements()): ?>
                    <?php echo $form->labelEx($model, 'verifyCode'); ?>
                    <div>
                        <?php
                        $this->widget('CCaptcha',
                            ['captchaAction' => '/users/captcha',]
                        );?>
                <?php endif; ?>
                    <?php echo Translated::model()->findByAttributes(array('param' => array('text_from_image')))->getName(); ?
                <?php echo $form->numberField($model, 'verifyCode'); ?>
                <?php echo $form->error($model, 'verifyCode'); ?>
                    <?php echo CHtml::submitButton('Зарегистрироваться', array('class' => 'btn btn-primary'));?>
                <?php $this->endWidget(); ?>

But for some reason, when you click on the Submit button, the client validation is not processed, and the controller action simply picks up $_POST .
Why doesn't client validation work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Khomenko, 2015-08-28
@EVOSandru6

The reason may be a JS error. This will explain both the lack of JS validation and the form submission. Take a look at the devtools browser console

E
EVOSandru6, 2015-08-29
@EVOSandru6

Thanks everyone for the replies, the error was in:
'id' => 'reg-form',
replaced with
'id' => 'users-form',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question