【问题标题】:Codeigniter Form Validation Rule one field should be bigger then otherCodeigniter 表单验证规则一个字段应该比其他字段大
【发布时间】:2017-06-22 05:12:21
【问题描述】:

我需要确保amount 字段大于amount_left 字段。

$config=array(
    array(
        'field'   => 'amount',
        'label'   => 'actual amount',
        'rules'   => 'trim|required'
    ),
    array(
        'field'   => 'amount_left',
        'label'   => 'amount left',
        'rules'   => 'trim|required'
    )
)

【问题讨论】:

    标签: php codeigniter validation


    【解决方案1】:

    试试这个代码:

    创建一个函数:

    希望它会起作用:

    function check_bigger($amount,$amount_left)
     {
        if ($amount >= $amount_left)
        {
            $this->form_validation->set_message('check_bigger', 'The First &/or Second fields have errors.');
            return false;       
        }
        else
       {
            return true;
       }
       }
    

    $v$this->input->post('amount_left');
    $config=array(
        array(
            'field'   => 'amount',
            'label'   => 'actual amount',
            'rules'   => 'trim|required|callback_check_bigger['.$v.']',
    
        ),
        array(
            'field'   => 'amount_left',
            'label'   => 'amount left',
            'rules'   => 'trim|required'
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 2011-01-29
      • 2013-09-30
      • 1970-01-01
      • 2022-12-14
      相关资源
      最近更新 更多