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.

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

报告相同问题?

悬赏问题

  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi
  • ¥15 ue2.6.12版本用的若以,安装gojs,引入import * as go from 'gojs';报错
  • ¥15 服务器上的网站安装php5.6版本
  • ¥15 ModuleNotFoundError: No module named 'torch.utils._import_utils' 是缺少什么
  • ¥15 请大咖一起探索iptv 直播源的hls通过反向代理解密
  • ¥100 寻找技术员 云闪付tn转h5输入卡号付款的链接 重酬!
  • ¥100 科大讯飞语音唤醒词,unbuntu环境,报错