【问题标题】:Either type validation in Codeigniter?Codeigniter 中的任何类型验证?
【发布时间】:2011-09-08 11:55:45
【问题描述】:

我有两个控件,一个是下拉菜单 (cmbCategories),第二个是输入文本框 (txtCategory)。

现在,我想添加验证。如果没有从 cmbCategories 下拉列表中选择 Category,它将查找 txtCategory 文本框。 如果两者都不存在,则应该给出错误,只需说“您必须从下拉列表中选择类别或输入类别文本框”。

我使用了以下类型验证规则,但它给出了意想不到的结果。

$this->form_validation->set_rules('cmbCategories','Category','required|is_natural|xss_clean');

$this->form_validation->set_rules('txtCategory','Category','required|min_length[5]|xss_clean');

我如何实现我正在寻找的功能?

【问题讨论】:

    标签: codeigniter validation


    【解决方案1】:

    CI 的验证方法只能在单个输入上调用,因此我认为您不能单独使用它们来完成您想要做的事情。我只会检查提交的帖子变量,并确保它们都不为空。

    if ($this->input->post('cmbCategories') == 0 && $this->input->post('txtCategory') == '')
    {
        // set error message and stop processing
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-18
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      相关资源
      最近更新 更多