【问题标题】:Codeigniter form validation - match one field to one of multiple fieldsCodeigniter 表单验证 - 将一个字段与多个字段之一匹配
【发布时间】:2017-10-28 23:44:16
【问题描述】:

是否可以通过表单验证将一个字段与多个字段之一匹配?

Like 字段 'answer' 匹配 'optiona' OR 'optionb' OR 'optionc' OR 'optiond'。

到目前为止我有这个。

正确答案的规则:

$this->form_validation->set_rules('answer', 'antwoord', 'required|max_length[100]');

选项 A、B、C 和 D 的规则。

$this->form_validation->set_rules('optiona', 'Optie A', 'required|max_length[100]');
$this->form_validation->set_rules('optionb', 'Optie B', 'required|max_length[100]');
$this->form_validation->set_rules('optionc', 'Optie C', 'required|max_length[100]');
$this->form_validation->set_rules('optiond', 'Optie D', 'required|max_length[100]');

【问题讨论】:

    标签: php codeigniter validation


    【解决方案1】:

    我完全不知道你在这里想要完成什么。我认为您必须使用回调。比如:

    public function check_answers($answer) {
        if (($answer == $this->input->post('optiona') || ($answer == $this->input->post('optionb')) {
            return TRUE;
        }
    }
    
    $this->form_validation->set_rules('answer', 'antwoord', 'required|max_length|callback_check_answers);
    

    希望这是有道理的,我猜。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多