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