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 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题