0

Currently I have data that it must has 1 title and 1 content, and randomly number (or none) link group (linktext and link ) , (as the it is dynamic generated) E.g. LinkText1 , Link1 , LinkText2, Link2....and so on. So, one example data is:

title:"abc"
content:"test"
linktext1:"yahoo"
link1:"http://yahoo.com"

my form is

<input type="text" name="linktext[]">
<input type="text" name="link[]">

The problem is, simply

$this->form_validation->set_rules('linkTxt[]', '連結標題', 'required');
$this->form_validation->set_rules('link[]', '連結地址', 'required');

is not working

I would like to if either linkTxt[0] or link[0] (or any pair) is exist , check the corresponding pair. If none of them exist (User can choose not to insert any link) (then no checking require) Thanks

4

1 回答 1

1

尝试:

if(set_value('linkTxt') or set_value('link') ){
$this->form_validation->set_rules('linkTxt[]', '連結標題', 'required');
$this->form_validation->set_rules('link[]', '連結地址', 'required');
}

基本上, Set_value('input_field') 如果没有 value 将返回 false 。(我不能 100% 确定这是否适用于数组输入,否则请尝试

$this->input->post('linkTxt[]')

如果仍然不起作用,可能会坚持一个 forloop 并测试每个 linkTxt 的值。

于 2013-10-09T21:30:58.370 回答