doumei8126 2019-04-09 17:46
浏览 42
已采纳

Codeigniter表单验证回调函数抛出错误消息

I have two input field carrying Product Price and Product Strike Price. In which Product Strike Price can be zero but cannot be less than or equal to product price. I created a callback function but it does not work it throws error as 'Unable to access an error message corresponding to your field name Product Strike Price.(price_check)'

Here is Callback function:

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;
                }
            }

And here is the Form validation:

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

Some one please help me in resolving the issue.

  • 写回答

1条回答 默认 最新

  • dqjjw04440 2019-04-10 06:43
    关注

    pass the the input product_price to your call back function like this.

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

    by this, it means you pass two arguments to your callback function so it would be like this in the next step.

     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;
                 }
        }
    

    Please let me know the result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?