2017-02-10 34 views
1

我找到了一個信用卡驗證器。但是,我不確定如何通過回調來使用它。我想要使​​用的功能需要4個輸入。不過,我現在只能通過表單驗證。希望有人能幫助我。Codeigniter如何使用信用卡幫手

控制器

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

回答

0

的回調需要一個功能之後被命名。

如果您有:

callback_check_default 

你需要呼籲的函數:

function check_default() { 
    //Your validation here 
    } 

是否回答你的問題?

+0

對不起!我沒有指定!我想要一個cardnumber_validation的回調 – JianYA