Я пытаюсь проверить номера кредитных карт, и до сих пор я могу получить от них результат. Однако всякий раз, когда происходит сбой, сообщение для проверки формы не появляется. Я пробовал несколько методов, включая установку обратного вызова. Я не уверен, что мне не хватает. Надеюсь, кто-нибудь может взглянуть и помочь мне.
контроллер
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');
$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');
// var_dump($this->cardnumber_validation($inputcardnumber,$inputcardtype));
if($this->form_validation->run()==false||$this->cardnumber_validation($inputcardnumber,$inputcardtype)==FALSE){
$this->index();
}else{
}
}
function cardnumber_validation($string = NULL,$cardtype=NULL) {
$this->load->helper('creditcardvalidation');
if(checkCreditCard ($string, $cardtype, $ccerror, $ccerrortext)) {
return TRUE;
}
else{
$this->form_validation->set_message("inputcardnumber", 'Invalid Card Number');
return FALSE;
}
}
function check_default($post_string){
return $post_string == '0' ? FALSE : TRUE;
}
Итак, я обнаружил, что вы можете сделать это, чтобы передать 2 переменные в обратный вызов
$this->form_validation->set_rules('inputcardnumber', 'Card Number', 'trim|required|xss_clean|callback_cardnumber_validation['.$this->input->post('inputcardtype').']');
Других решений пока нет …