<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'tag-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'tagname'); ?>
<?php echo $form->textField($model,'tagname',array('size'=>20,'maxlength'=>32)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'tagtype'); ?>
<?php echo $form->radioButtonList($model,'tagtype'array(1=>"普通TAG",2=>"系统默认TAG"),array('separator'=>'','labelOptions'=>array('class'=>'tagtypelabel'))); ?>
</div>
<?php echo $form->errorSummary($model); ?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? '添加' : '修改'); ?>
</div>
<?php $this->endWidget(); ?>
public function rules()
{
return array(
array('tagname,tagtype', 'required'),
array('tagtype', 'numerical', 'integerOnly'=>true),
array('tagname', 'length', 'max'=>32),
array('tagname', 'match', 'pattern'=>'/^[\x{4e00}-\x{9fa5}A-Za-z0-9]+$/u',
'message'=>'标签不合法,必须为汉字、字母或者数字!'),
array('tagname', 'checktagname', 'on'=>'create,update'),//插入TAG时检查是否已经存在该tag
array('tagid, tagname, tagtype', 'safe', 'on'=>'search'),
);
}
public function checktagname($attribute,$params){
$oldtag = Tag::model()->findByAttributes(array('tagname'=>$this->tagname));
if($oldtag->tagid > 0){
$this->addError($attribute, '该TAG已经存在!');
}
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array(
array('password', 'passwordStrength', 'strength'=>self::STRONG),
);
}
/**
* check if the user password is strong enough
* check the password against the pattern requested
* by the strength parameter
* This is the 'passwordStrength' validator as declared in rules().
*/
public function passwordStrength($attribute,$params)
{
if ($params['strength'] === self::WEAK)
$pattern = '/^(?=.*[a-zA-Z0-9]).{5,}$/';
elseif ($params['strength'] === self::STRONG)
$pattern = '/^(?=.*\d(?=.*\d))(?=.*[a-zA-Z](?=.*[a-zA-Z])).{5,}$/';
if(!preg_match($pattern, $this->$attribute))
$this->addError($attribute, 'your password is not strong enough!');
}
class passwordStrength extends CValidator
{
public $strength;
private $weak_pattern = '/^(?=.*[a-zA-Z0-9]).{5,}$/';
private $strong_pattern = '/^(?=.*\d(?=.*\d))(?=.*[a-zA-Z](?=.*[a-zA-Z])).{5,}$/';
...
}
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object,$attribute)
{
// check the strength parameter used in the validation rule of our model
if ($this->strength == 'weak')
$pattern = $this->weak_pattern;
elseif ($this->strength == 'strong')
$pattern = $this->strong_pattern;
// extract the attribute value from it's model object
$value=$object->$attribute;
if(!preg_match($pattern, $value))
{
$this->addError($object,$attribute,'your password is too weak!');
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有