Codeigniter表单验证回调函数引发错误消息

时间:2019-04-09 17:46:23

标签: php codeigniter codeigniter-3

我有两个输入字段,分别包含产品价格和产品执行价格。产品执行价格可以为零,但不能小于或等于产品价格。我创建了一个回调函数,但不起作用,它会引发错误,因为“无法访问与您的字段名称Product Strike Price。(price_check)相对应的错误消息”

这是回调函数:

function price_check(){
                $pd_price = intval($this->input->post('product_price'));
                $pd_strikeprice = intval($this->input->post('product_strike_price'));

                if($pd_strike_price > $pd_price OR $pd_strike_price = 0){
                    return true;
                }else{

                    $this->form_validation->set_message('price_check', 'Product Strike Price can be zero(0) but cannot be less than or equal to Product Price.');
                return false;
                }
            }

这是表单验证:

$this->form_validation->set_rules('product_strike_price', 'Product Strike Price', 'trim|required|is_natural|callback_price_check');

请有人帮我解决问题。

1 个答案:

答案 0 :(得分:0)

将输入的 product_price 传递给这样的回调函数。

callback_price_check['.$this->input->post('product_price').'] 

由此,这意味着您将两个参数传递给回调函数,以便在下一步中像这样。

 public function price_check($pd_strikeprice, $pd_price){
         if($pd_strike_price > $pd_price || $pd_strike_price = 0){
                 return true;
         }else{

                 $this->form_validation->set_message('price_check', 'Product Strike Price can be zero(0) but cannot be less than or equal to Product Price.');
                 return false;
             }
    }

请让我知道结果。

相关问题