我正在使用 yii 1.1.12。我的一个注册表单没有显示任何错误,验证工作正常,但唯一的问题是错误消息以样式显示display:none;
,因此它不可见,如下所示。任何帮助都非常可观。
模型
<?php
/**
* This is the model class for table "users".
*
* The followings are the available columns in table 'users':
* @property integer $id
* @property string $user_name
* @property string $password
* @property string $email
* @property string $premium_expiry_date
* @property integer $active
*/
class Users extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Users the static model class
*/
public $name;
public $date;
public $month;
public $year;
public $gender;
public $religion;
public $caste;
public $mobile;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'users';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('user_name, password, email, premium_expiry_date, active', 'required','on'=>array('registration')),
array(', password, email, premium_expiry_date, active', 'required','on'=>array('registration')),
array('active', 'numerical', 'integerOnly'=>true),
array('user_name, email', 'length', 'max'=>50),
array('password', 'length', 'max'=>100),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('name, date, month, year, gender, religion, caste, mobile, email, password', 'required','on'=>array('reg_home')),
array('email', 'unique'),
array('date', 'length', 'max'=>2,'on'=>array('reg_home')),
array('email', 'email'),
array('email', 'length', 'max'=>50,'on'=>array('reg_home')),
array('name', 'length', 'max'=>30,'on'=>array('reg_home')),
array('month', 'length', 'max'=>20,'on'=>array('reg_home')),
array('year', 'length', 'max'=>4,'on'=>array('reg_home')),
array('gender', 'length', 'max'=>6,'on'=>array('reg_home')),
array('religion', 'length', 'max'=>4,'on'=>array('reg_home')),
array('id, user_name, password, email, premium_expiry_date, name, date, month, year, gender, religion, caste, mobile, active', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'user_name' => 'User Name',
'password' => 'Login Password',
'email' => 'Email',
'premium_expiry_date' => 'Premium Expiry Date',
'active' => 'Active',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('user_name',$this->user_name,true);
$criteria->compare('password',$this->password,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('premium_expiry_date',$this->premium_expiry_date,true);
$criteria->compare('active',$this->active);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
控制器
public function actionIndex()
{
$model=new Users('reg_home');
if(isset($_POST['Users']))
{
$model->attributes=$_POST['Users'];
$model->validate();
// print_r($model->getErrors());
if($model->save())
{
/* echo 'done';
exit;*/
}
else
{
/*print_r($model->getErrors()); exit;
echo '!!!!!!!!!!!';
exit;*/
}
////print_r($model->validators); exit;
//print_r($model->attributes);
}
//$model->validate();
// $ww=new Users
$pages_model=new Pages;
$welcome_content=$pages_model->find('page_heading=:page_heading',array(':page_heading'=>'Home'));
$welcome_content=$welcome_content['page_content']; //echo $welcome_content;exit;
$db_cretiria=new CDbCriteria(array('condition'=>'success_couple=:success_couple','params'=>array(':success_couple'=>1),'order'=>'id DESC','limit'=>2));
//print_r(count($db_cretiria)); exit;
$gallery_modle=new Gallery;
$success_couple=$gallery_modle->findAll($db_cretiria);
foreach($success_couple as $val)
{
$success_couple_array[$val['id']]=$val['image_new_name'];
}
$religion_model=new Religion;
$religion=$religion_model->findAll();
foreach($religion as $val)
{
$religion_array[$val['id']]=$val['religion'];
}
$this->layout='matrimony';
//print_r($model->getErrors()); exit;
$this->render('index',array('welcome_content'=>$welcome_content,'success_couple_array'=>$success_couple_array,'model'=>$model,'religion_array'=>$religion_array));
}
看法:
<script type="text/javascript" src="<?php echo Yii::app()->getBaseUrl(true); ?>/js/common_front.js"></script>
<section id="gallery">
<div class="gal-slide">
<div class="slider-wrapper theme-default">
<div id="slider" class="nivoSlider">
<img src="<?php echo Yii::app()->getBaseUrl(true); ?>/images/slide-1.png" width="562" height="350" alt="slide">
<img src="<?php echo Yii::app()->getBaseUrl(true); ?>/images/slide-2.png" width="562" height="350" alt="slide">
</div>
</div>
</div>
<div class="gal-form">
<div id="tabs">
<ul>
<li><a href="#tab-1">Register</a></li>
<li><a href="#tab-2">Search</a></li>
</ul>
<div id="tab-1">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'reg-form-reg-form',
'enableAjaxValidation'=>false,
));
// print_r($model->getErrors());
// print_r($form->error($model,'name'));exit;
//echo $form->errorSummary($model); exit;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php echo $form->labelEx($model,'name'); ?>
</td>
<td width="10"> </td>
<td>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>
</td>
</tr>
<tr>
<td>Date Of Birth *</td>
<td> </td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="84">
<?php for($i=1;$i<=31;$i++){$date[$i]=$i;} ?>
<?php echo $form->dropDownList($model,'date',$date); ?>
<?php echo $form->error($model,'date'); ?>
</td>
<td width="84">
<?php
$month=array('January'=>'January','February'=>'February','March'=>'March','April'=>'April','May'=>'May','June'=>'June','July'=>'July','August'=>'August','September'=>'September','October'=>'October','November'=>'November','December'=>'December');
echo $form->dropDownList($model,'month',$month); ?>
<?php echo $form->error($model,'month'); ?></td>
<td> <?php
$last_year=date('Y')-18;
$last_year_last=$last_year-85;
$year_range=range($last_year,$last_year_last);
foreach($year_range as $val) // atleast 18 age
{
$year_val[$val]=$val;
}
echo $form->dropDownList($model,'year',$year_val);
echo $form->error($model,'year'); ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Gender *</td>
<td> </td>
<td><label>
<input type="radio" name="Users[gender]" id="male" value="male">
Male
<input type="radio" name="Users[gender]" id="male2" value="female">
Female
</label></td>
</tr>
<tr>
<td><?php echo $form->labelEx($model,'religion'); ?>
</td>
<td> </td>
<td><?php echo $form->dropDownList($model,'religion',$religion_array,array('class'=>'selet', 'onClick'=>"javascript:list_caste(this);")); ?>
<?php echo $form->error($model,'religion'); ?></td>
</tr>
<tr>
<td><?php echo $form->labelEx($model,'caste'); ?></td>
<td> </td>
<td><?php echo $form->dropDownList($model,'caste',array(''=>'select religion'),array('class'=>'selet',)); ?>
<?php echo $form->error($model,'caste'); ?>
</select></td>
</tr>
<tr>
<td><?php echo $form->labelEx($model,'mobile'); ?></td>
<td> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><select name="date6" id="date6"><option value="+91">+91</option>
</select></td>
<td><?php echo $form->textField($model,'mobile',array('class'=>'mobile')); ?>
<?php echo $form->error($model,'mobile'); ?></td>
</tr>
</table></td>
</tr>
<tr>
<td><?php echo $form->labelEx($model,'email'); ?></td>
<td> </td>
<td><?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?></td>
</tr>
<tr>
<td><?php echo $form->labelEx($model,'password'); ?></td>
<td> </td>
<td><?php echo $form->passwordField($model,'password'); ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><label>
<?php echo CHtml::submitButton('Register Free',array('class'=>'subt')); ?>
</label></td>
</tr>
</table>
<?php $this->endWidget(); ?>
</div>
<div id="tab-2">
<form action="search.php" method="get">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Looking For</td>
<td width="10"> </td>
<td>
<select class="selet" name="listbox" id="listbox">
<option>Bride</option>
<option>Groom</option>
</select>
</td>
</tr>
<tr>
<td>Age</td>
<td> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="112"><select name="listbox2" id="listbox2">
<option>select</option>
<option>18</option>
</select></td>
<td width="57">To</td>
<td><select name="listbox3" id="listbox3">
<option>Select</option>
<option>22</option>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td>Height(CM)</td>
<td> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="112"><select name="listbox4" id="listbox4">
<option>select</option>
<option>18</option>
</select></td>
<td width="57">To</td>
<td><select name="listbox4" id="listbox5">
<option>Select</option>
<option>22</option>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td>With Photo</td>
<td> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><label>
<input type="checkbox" name="tick" id="tick" />
</label></td>
<td><label>
<input class="subt" type="submit" name="button" id="button" value="Search" />
</label></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Member id</td>
<td> </td>
<td><label>
<input type="text" name="textfield" id="textfield" />
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input class="subt" type="submit" name="button2" id="button2" value="Search" /></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</section>
<section id="content">
<div class="left">
<div class="text">
<?php echo $welcome_content; ?>
</div>
<div class="premia">
<h2>Premium Display</h2>
<ul>
<li>
<img src="<?php echo Yii::app()->getBaseUrl(true); ?>/images/pre.png" width="130" height="79" alt="groum">
<span> <span class="name">Sasi </span><span class="yer">25yrs</span></span><span class="id">Profile ID : MI-230001 </span>
</li>
<li><img src="<?php echo Yii::app()->getBaseUrl(true); ?>/images/pre.png" width="130" height="79" alt="groum"><span> <span class="name">Sasi </span><span class="yer">25yrs</span></span>
<span class="id">Profile ID : MI-230001 </span></li>
<li><img src="<?php echo Yii::app()->getBaseUrl(true); ?>/images/pre.png" width="130" height="79" alt="groum"><span> <span class="name">Sasi </span><span class="yer">25yrs</span></span>
<span class="id">Profile ID : MI-230001 </span></li>
<li><img src="<?php echo Yii::app()->getBaseUrl(true); ?>/images/pre.png" width="130" height="79" alt="groum"><span> <span class="name">Sasi </span><span class="yer">25yrs</span></span>
<span class="id">Profile ID : MI-230001 </span></li>
<div class="clear"></div>
</ul>
</div>
</div>
<div class="right">
<div class="sucouple">
<h3>Success Couples</h3>
<ul>
<?php
$base= Yii::app()->getBaseUrl(true);
//print_r($success_couple_array);
foreach($success_couple_array as $val)
{
echo "<li><img src=\"$base/gallery/thumb/$val\" width=\"199\" height=\"124\" alt=\"couples\"></li>";
}
?>
</ul>
</div>
</div>
<div class="clear"></div>
</section>