title: exit function if error - cakephp
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>function confirm() {
  
      //This view contains the form, when user submits they go to checkout view
      if (isset($data)){$this-&gt;data = $data;}
  
      $this-&gt;set('redirect_to', 'checkout');  
  
  }
  
  function checkout(){
  
     if(!empty($this-&gt;data['User']['card_number'])){
          $check_card = $this-&gt;BillingValidation-&gt;validate_card($this-&gt;data['User']['card_number']);
  
          if($check_card['valid']!=false){
              // card is valid !
  
          } else {        
              $msg[0][] = $check_card['error'];
              $flashmsg = implode('&lt;br /&gt;',$msg[0]).implode('&lt;br /&gt;',$msg[1]);
                  $this-&gt;Session-&gt;setFlash(__($flashmsg,
                            true),'default', array('class' =&gt; 'flash-message-success'));
  
              //if credit card is invalid go back to confirm view
  
              $this-&gt;autoRender = false;
              $d = new Dispatcher();
              $d-&gt;dispatch(array("controller" =&gt; "res", "action" =&gt; "confirm"),array("data" =&gt; $this-&gt;data));
          }
      } 
            //if credit card ok then continues to process form
  }
  </code></pre>