【问题标题】:How to validate value of array in codeigniter如何在codeigniter中验证数组的值
【发布时间】:2017-12-19 06:24:47
【问题描述】:

我正在使用codeigniter 插入数据。 这是我得到的帖子数据数组。

问题:我正在发送 app_soft_idslang_idsworking_days 表单我的 HTML 表单,所以我在帖子中得到它,如此处的帖子数组所示。但是codeigniter 没有验证这三个值。

如何验证这三个值? codeigniter 验证后显示此错误。我不明白我怎么可能正确发送数据但 CI 验证仍然没有得到它。

应用程序 ID 字段是必需的。

语言 ID 字段是必需的。

工作日字段是必需的。

这是我的帖子数组。

Array
(
    [app_soft_ids] => Array
        (
            [0] => 66
            [1] => 68
        )

    [lang_ids] => Array
        (
            [0] => 4
            [1] => 5
        )
    [working_days] => Array
        (
            [0] => 4
        )

    [shift] => Y    
    [status] => O
    [expiry_date] => 10/07/2017
)

这是我的验证码:

$config = array(
    'app_validation' => array(
        array(
                'field' => 'app_soft_ids',
                'label' => 'Application IDs',
                'rules' => 'required|numeric'
        ),
        array(
                'field' => 'lang_ids',
                'label' => 'Langusge IDs',
                'rules' => 'required|numeric'
        ),
        array(
                'field' => 'working_days',
                'label' => 'Working Days',
                'rules' => 'required|numeric'
        ),
        array(
                'field' => 'shift',
                'label' => 'Shift',
                'rules' => 'required|trim|max_length[1]|'
        )
    )
);

【问题讨论】:

标签: arrays codeigniter validation


【解决方案1】:

感谢 kumar_v 评论,我得到了验证数组的方法,只需添加 [] init。

$config = array(
    'app_validation' => array(
        array(
                'field' => 'app_soft_ids[]',
                'label' => 'Application IDs',
                'rules' => 'required|numeric'
        ),
        array(
                'field' => 'lang_ids[]',
                'label' => 'Langusge IDs',
                'rules' => 'required|numeric'
        ),
        array(
                'field' => 'working_days[]',
                'label' => 'Working Days',
                'rules' => 'required|numeric'
        ),
        array(
                'field' => 'shift',
                'label' => 'Shift',
                'rules' => 'required|trim|max_length[1]|'
        )
    )
);

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2011-01-01
    • 2016-12-14
    • 1970-01-01
    • 2011-07-10
    • 2012-01-02
    相关资源
    最近更新 更多