douzhi3779 2014-07-17 09:36
浏览 47
已采纳

too long

I have a Yii form that uses the Yii Bootstrap library, on form submission if there is an error in any of the fields the field is highlighted and that individual error is shown in red text just below the corresponding input text field.

I'd like to display all the errors at the top of the page just above the form as well, my code looks like the following:

I'd like to have the errors listed one after the other at the top of the form, any ideas on the best way to achieve this?

<?php if (!$model->isNewrecord) $this->renderPartial('partials/_totals', compact('model'));?>

<?php $form = $this->beginWidget('application.widgets.bootstrap.TbActiveFormExt', array(
'id'                    => get_class($model),
'type'                  => 'horizontal',
'enableAjaxValidation'  => true,
'clientOptions'             => array(
    'validateOnSubmit'      => true,
    'validateOnChange'      => false,
    'validateOnType'        =>false,
),
'htmlOptions'           => array(
    'class'                 => '',
    'autocomplete'          => 'off'
),
)); ?>
<?php echo $form->hiddenField($model, 'activetab' ); ?>

<?php $this->beginWidget('CClipWidget', array('id'=>'t1')); ?>
    <div class="row-fluid">
        <div class="inner">
            <fieldset class="span12">
                <legend>User Details</legend>
                <div class="row-fluid">
                    <div class="span6">
                        <?php echo $form->textFieldRow($model, 'username', array('class'=>'span12')); ?>
                        <?php if ($model->isNewRecord):?>
                            <?php echo $form->passwordFieldRow($model, 'password', array('value'=>'','class'=>'span12')); ?>
                            <?php echo $form->passwordFieldRow($model, 'password_repeat', array('value'=>'', 'class'=>'span12', 'hint' => '<i class="icon-info-sign"></i> If you leave the password fields empty we will default it to \'mystickers\'.')); ?>
                        <?php else:?>
                            <?php echo $form->passwordFieldRow($model, 'new_password', array('value'=>'', 'class'=>'span12')); ?>
                            <?php echo $form->passwordFieldRow($model, 'new_password_repeat', array('value'=>'', 'class'=>'span12', 'hint' => '<i class="icon-info-sign"></i> Enter a new password only if you wish to change the current one.')); ?>
                        <?php endif; ?>
                        <?php echo $form->textFieldRow($model, 'firstname', array('class'=>'span8')); ?>
                        <?php echo $form->textFieldRow($model, 'surname', array('class'=>'span8')); ?>

                        </div>
                        <div class="span6">
                            <?php if ($model->isNewRecord):?>
                            <?php echo $form->dropDownListRow($model, 'gender', $model->genderOptions, array( 'empty' => '-- Select --', 'class'=>'span12')); ?>
                        <?php else: ?>
                            <?php echo $form->dropDownListRow($model, 'gender', $model->genderOptions, array('class'=>'span12')); ?>
                        <?php endif; ?>
                        <?php echo $form->textFieldRow($model, 'year_id', array('class'=>'span2')); ?>
                        <?php echo $form->textFieldRow($model, 'form_name', array('class'=>'span12')); ?>
                        <?php echo $form->textFieldRow($model, 'House', array('class'=>'span12')); ?>
                        <?php if ($model->isNewRecord): ?>
                            <?php if (user()->hasAuth(Group::GROUP_ADMIN, 'equal') && !user()->data->organisation->hasViewOrg): ?>
                                <?php echo $form->dropDownListRow($model, 'organisation_id', CHtml::listData($model->organisations, 'organisation_id', 'organisation_name'), array('prompt' => '-- Select --', 'class'=>'span9', 'value' => user()->getState('view_org'))); ?>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
<?php $this->endWidget(); ?>

<?php $this->beginWidget('CClipWidget', array('id'=>'t2')); ?>
    <div class="row-fluid">
        <div class="inner">
            <fieldset class="span12">
                <legend>Unique Label Information</legend>
                <div class="row-fluid">
                    <div class="span6">
                        <?php echo $form->textFieldRow($model, 'Unique1', array('class'=>'span12')); ?>
                        <?php echo $form->textFieldRow($model, 'Unique2', array('class'=>'span12') ); ?>
                        <?php echo $form->textFieldRow($model, 'Unique3', array('class'=>'span12') ); ?>
                        <?php echo $form->textFieldRow($model, 'Unique4', array('class'=>'span12') ); ?>
                        <?php echo $form->textFieldRow($model, 'Unique5', array('class'=>'span12')); ?>
                        <?php echo $form->textFieldRow($model, 'Unique6', array('class'=>'span12') ); ?>
                        <?php echo $form->textFieldRow($model, 'Unique7', array('hint' => '<i class="icon-info-sign"></i> You can change these unique label titles on your settings page.', 'class'=>'span12') ); ?>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
<?php $this->endWidget(); ?>

<?php $this->widget('bootstrap.widgets.TbTabs', array(
        'type'          => 'tabs',
        'placement'     => 'left',
        'htmlOptions'   => array(
            'class'         => 'clearfix',
        ),
        'events'    => array(
            'click' => 'js:function(e){$("#StudentDetailsForm_activetab").val(e.target.hash.substring(1))}'
        ),
        'tabs'          => array(
            array(
                'label'     => 'Main',
                'content'   => $this->clips['t1'],
                'active'    => !isset($activeTab) || $activeTab == 'yw0_tab_1',
            ),
            array(
                'label'     => 'Unique Label Information',
                'content'   => $this->clips['t2'],
                'active'    => isset($activeTab) && $activeTab == 'yw0_tab_2',
            )
        )
    )); ?>

    <div class="form-actions">
        <?php $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType'    => 'submit',
            'type'          => 'success',
            'icon'          => 'ok white',
            'label'         => 'Save Settings',
            'htmlOptions'   => array(
                'class'         => 'pull-right'
            )
        )); ?>

        <?php $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType'    => 'reset',
            'icon'          => 'remove',
            'label'         => 'Reset',
            'htmlOptions'   => array(
                'class'         => 'pull-right',
                'style'         => 'margin:0 10px;'
            )
        )); ?>
        <?php $this->widget('bootstrap.widgets.TbButton', array(
            'icon'          => 'arrow-left',
            'label'         => 'Cancel',
            'url'           => $overview ? '/site/overview/'.$overview : '/site/myuser/index',
            'htmlOptions'   => array(
                'style'         => 'margin:0 10px;'
            )
        )); ?>
    </div>
<?php $this->endWidget(); ?>
  • 写回答

1条回答 默认 最新

  • douju6542 2014-07-17 09:40
    关注

    You can try

     <?php echo $form->errorSummary($model); ?>
    

    just after your bootstrap form widget.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路