【问题标题】:Codeigniter how to use credit card helperCodeigniter 如何使用信用卡助手
【发布时间】:2017-06-28 23:19:35
【问题描述】:

我找到了一个信用卡验证器。但是,我不确定如何将它与回调一起使用。我要使用的功能需要 4 个输入。但是我现在只能通过表单验证。希望有人可以帮助我。

控制器

public function next(){
        $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
        $this->form_validation->set_rules('inputcardtype','Select Card Type','required|callback_check_default');
        $this->form_validation->set_message('check_default', 'Please select the month of expiration');
        $this->form_validation->set_rules('inputcardnumber', 'Card Number', 'trim|required|xss_clean|callback_cardnumber_validation');
        $this->form_validation->set_rules('inputexpirationdatemonth','Select Month','required|callback_check_default');
        $this->form_validation->set_message('check_default', 'Please select the month of expiration');
        $this->form_validation->set_rules('inputexpirationdateyear','Select Year','required|callback_check_default');
        $this->form_validation->set_message('check_default', 'Please select the year of expiration');
        $this->form_validation->set_rules('inputnameoncard', 'Name on Card', 'trim|required|xss_clean');

        $inputcardnumber = $this->input->post('inputcardnumber');
        $inputcardtype = $this->input->post('inputcardtype');
        if($this->form_validation->run()==false){
            $this->index();
        }else{

        }

    }

    function cardnumber_validation($string = NULL) {
         $this->load->helper('creditcardvalidation'); 

         if(checkCreditCard ($string, $cardtype, $ccerror, $ccerrortext)) {
            return TRUE;
        } 
        else{
            $this->form_validation->set_message("cardnumber_validation", 'The %s is not valid.');
            return FALSE;
        }
    }

【问题讨论】:

    标签: php forms codeigniter


    【解决方案1】:

    回调需要以函数命名。

    如果你有:

    callback_check_default
    

    你需要有一个函数叫做:

        function check_default() {
         //Your validation here
      }
    

    这能回答你的问题吗?

    【讨论】:

    • 对不起!我没有具体说明!我想要 cardnumber_validation 的回调
    猜你喜欢
    • 2014-12-04
    • 1970-01-01
    • 2010-12-25
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    相关资源
    最近更新 更多