I have a function to check if a credit card is valid or not. If it is then continue to enter the details from the form into the database. But if it is not then display the message that is passed.
The problem is that if there is an issue with the credit card the message is passed but the rather then exiting the function so that it does not try to continue and add the data from the form, it adds the data.
I am not sure how to stop. The following code was written for me, seems to create a new dispatch and try to go back to the previous function confirm.
function confirm() {
//This view contains the form, when user submits they go to checkout view
if (isset($data)){$this->data = $data;}
$this->set('redirect_to', 'checkout');
}
function checkout(){
if(!empty($this->data['User']['card_number'])){
$check_card = $this->BillingValidation->validate_card($this->data['User']['card_number']);
if($check_card['valid']!=false){
// card is valid !
} else {
$msg[0][] = $check_card['error'];
$flashmsg = implode('<br />',$msg[0]).implode('<br />',$msg[1]);
$this->Session->setFlash(__($flashmsg,
true),'default', array('class' => 'flash-message-success'));
//if credit card is invalid go back to confirm view
$this->autoRender = false;
$d = new Dispatcher();
$d->dispatch(array("controller" => "res", "action" => "confirm"),array("data" => $this->data));
}
}
//if credit card ok then continues to process form
}
I used exit() and that seemed to work