可以在同一元素上的CI中使用验证规则两次 [英] Can i Use validation rules in CI on the same element twice
问题描述
我已在配置文件的form_validation文件中定义了所有规则
ex
$ config = array(
'basic'=> array(
array(
'field'=>'name',
'label'=>'Name'
'rules'=>'alpha'
),
array(
'field'=>'age',
'label'=> Age',
'rules'=>'alpha'
),
array(
'field'=>'city',
'label' >'City',
'rules'=>'alpha'
)
),
'
array(
'field'=>'name',
'label'=>'Name',
'rules'=>'required'$ b $
array(
'field'=>'age',
'label'=>'Age',
'rules'=>'required'
),
array(
'field'=> 'city',
'label'=> 'City',
'rules'=> 'required'
),
),
);
$ config [submitfinal] = array_merge($ config ['basic'],$ config ['mand']);
我一直试图实现的是有两个按钮,其中一个按钮被称为(savenow)当用户按下它时,它应该仅验证非空数据,而另一个按钮是(保存和完成),当用户按下它,它应该验证非空以及其他规则集,所以我有两个组分别定义并调用它们(savenow功能),当我尝试合并这两个组的基本组验证似乎不工作
注意:我已经应用验证的保持它们的分离状态表示无需合并它们,只需更新任务数组为
'mand'=> array(
array(
'field'=>'name',
'label'=>'Name',
'rules'=>'required | alpha '
),
array(
'field'=>'age',
'label'=>'Age',
'rules'=> ;'required | alpha'
),
array(
'field'=>'city',
'label'=>'City',
'rules'=>'required | alpha'
),
),
b $ b
然后在点击功能上调用一个特定的组。
I Have Defined my all rules in a form_validation file in config file
e.x
$config = array(
'basic' => array(
array(
'field' => 'name',
'label' => 'Name',
'rules' => 'alpha'
),
array(
'field' => 'age',
'label' => 'Age',
'rules' => 'alpha'
),
array(
'field' => 'city',
'label' => 'City',
'rules' => 'alpha'
)
),
'mandate' => array(
array(
'field' => 'name',
'label' => 'Name',
'rules' => 'required'
),
array(
'field' => 'age',
'label' => 'Age',
'rules' => 'required'
),
array(
'field' => 'city',
'label' => 'City',
'rules' => 'required'
),
),
);
$config["submitfinal"] = array_merge($config['basic'], $config['mandate']);
What i have been trying to achieve is there are two buttons in which one button is called (savenow) where when the user presses it, it should validate only for nonempty data and the other button is (save and complete) when the user presses it ,it should validate for non empty as well as other rule sets , so i had two groups defined separately and called them for (savenow feature) and when i try to combine both the groups the validation of basic group seems to be not working
Note: I Have applied validation on the same fieldnames in both the groups can you suggest me like how to go further on implementing save and complete feature.
keep them seperate mean no need to merge them, just update mandate array as
'mandate' => array(
array(
'field' => 'name',
'label' => 'Name',
'rules' => 'required|alpha'
),
array(
'field' => 'age',
'label' => 'Age',
'rules' => 'required|alpha'
),
array(
'field' => 'city',
'label' => 'City',
'rules' => 'required|alpha'
),
),
then just call one specific group on click function.
这篇关于可以在同一元素上的CI中使用验证规则两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!