注册页面中我的 yii 表单的字段被渲染了两次!!有人可以帮我找出是什么原因造成的吗?
这是来自控制器的代码:
public function actionRegister()
{
$form=new Users;
// collect user input data
if(isset($_POST['Users']))
{
$form->attributes=$_POST['Users']; // set all attributes with post
// NOTE Changes to any $form->value have to be performed BEFORE $form-validate()
// or else it won't save to the database.
// validate user input and redirect to previous page if valid
if($form->validate())
{
// save user registration
$form->save();
$this->redirect(Yii::app()->createUrl('site/login'));
}
}
// display the registration form
$this->render('register',array('form'=>$form));
}
这是视图中的代码:
<?php $pagetitle = "Hubylon | Register"; ?>
<?php $this->breadcrumbs=array('Register'); ?>
<div class="yiiForm">
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::errorSummary($form); ?>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'username'); ?>:</td>
<td><?php echo CHtml::activeTextField($form,'username'); ?></td>
<td><?php echo CHtml::error($form,'username',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'password'); ?>:</td>
<td><?php echo CHtml::activePasswordField($form,'password'); ?></td>
<td><?php echo CHtml::error($form,'password',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'confirmPassword'); ?>:</td>
<td><?php echo CHtml::activePasswordField($form,'confirmPassword'); ?></td>
<td><?php echo CHtml::error($form,'confirmPassword',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td><?php echo CHtml::activeLabel($form,'first_name'); ?>:</td>
<td><?php echo CHtml::activeTextField($form,'first_name'); ?></td>
<td><?php echo CHtml::error($form,'first_name',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td><?php echo CHtml::activeLabel($form,'birthdate'); ?>:</td>
<td><?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'attribute'=>'birthdate',
'model' => $form,
//'language'=>Yii::app()->language=='en' ? 'en' : null,
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'defaultDate'=>$form->birthdate,
'buttonImage'=>Yii::app()->baseUrl.'/images/icons.date.png',
'buttomImageOnly'=>true,
'showAnim'=>'fold',
'showOn'=>'button',
'yearRange'=>'1900',),
'htmlOptions'=>array(
'style'=>'width:80px;vertical-align:top'
),
));
?></td>
</tr>
</table>
</div>
<div class="action">
<?php echo CHtml::submitButton('Register'); ?>
</div>
<?php echo CHtml::endForm(); ?>
谢谢!