0
大家好,thansk给大家阅读。yii如何根据下拉选项执行动态验证
Iam制作一个网站只是为了好玩和学习yii。该网站是一个可用于举报盗版链接的应用程序。
我有一个输入字段,我提供了一个链接,比我有一个下拉菜单,您可以从中选择您要提交的链接类型。根据您选择的值,我希望在提交的链接上执行不同的验证规则。如果我不清楚我的完成情况,请随时访问www.youtubetv.it,在主页上您将看到一个输入字段和一个下拉菜单。
代码如下;在模型
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('category, link', 'required'),
array('id_user', 'numerical', 'integerOnly' => true),
array('link', 'length', 'max' => 999),
array('link', 'url',
'allowEmpty' => false,
'defaultScheme' => null,
//'pattern' => 'esspressione regolare',
'message' => 'The specified model does not exist.',
'validSchemes' => (array('http', 'https'))
),
array('category, web_page', 'length', 'max' => 255),
array('creation_date', 'default',
'value' => new CDbExpression('NOW()'),
'setOnEmpty' => false,
'on' => 'insert'),
array('id_public_link, category, id_user, link, creation_date', 'safe', 'on' => 'search'),
);
}
<div class="span4">
<div class="input-prepend"><span class="add-on" style="height: 50px;">
<i class="icon-4x icon-globe" style="line-height: 54px;"></i></span>
<?php
echo $form->textField($model, 'link', array(
'prepend' => '<i class="icon-4x icon-globe" style="line-height: 54px;"></i>',
'class' => 'span12', 'maxlength' => 999,
'style' => 'height:60px;font-size: 22px;width: 400px;',
));
?>
</div>
</div>
<div class="span4 offset1">
<?php
echo $form->dropDownList($model, 'category', CHtml::listData(Lookup::model()->findAll('type="kind"'), 'code', 'name'), array(
'prompt' => 'Select Type',
'class' => 'span12',
'style' => 'height:60px;font-size: 22px;',
));
?>
</div>
当前验证规则我将不胜感激,如果有人可以告诉我的,我怎么能验证“URL”如果有人从下拉列表中选择电影的例子。
请随时要求澄清,如果我不清楚
嘿感谢指向我在正确的方向, 1')//正如我从你的网站'1'所假设的那样是一个电影 $ model-> scenario ='urlcheck';像这样的工作 – Gunnit 2013-03-25 16:40:10