Welcome Guest, Not a member yet? Register   Sign In
Finish the execution of code after encountering validation
#1

[eluser]rochellecanale[/eluser]
Hello guys just wanna ask how can i cut the execution of code when i met the validation. Here's my sample code in view.

Code:
$memberid = $this->input->post('id');
    $payment = $this->input->post('payment');
    $subtotal =  $this->session->userdata('subtotal');
    $change = $payment-$subtotal;
    
    $payment_method = $this->input->post('payment_method'); //get payment method
    
    //get e-wallet balance
    if($payment_method == 'E-WALLET'){
        $sql = "SELECT running_balance FROM points_ledger WHERE fkmember={$memberid}";
        $getBalance = $this->db->query($sql);
        
        //assign e-wallet amount to variable names payemt_balance
        foreach($getBalance->result_array() as $data){
            $payment_balance = $data['running_balance'];
        }
        
        /*********************************************************************/
        /** IF E WALLET METHOD,VALIDATE IF SUFFICIENT FOR PAYMENT AND  EXIT **/
        /** CODE AND IF WALLET IS ENOUGH TO PURCHASE PROCEED TO RECEIPT ******/
        /** PRINTING AND SAVE TO DATABASE THE SALES TRANSACTION **************/

        if($payment_balance < $subtotal){
        echo "[removed]
              alert('You are insufficient of points. Use CASH for method payment instead.');
              history.back();
              [removed]";
        }
    }

// REST OF CODE INCLUDING PRINTING RECEIPT AND SAVE SALES TRANSACTION...

My problem is when i met the validation (Meaning the user chose ewallet for method and the ewallet amount is not sufficient for payment). My code continue to execute it prompts the user 'You are insufficient of points. Use CASH for method payment instead.' And it continue to save and the page back to the sales transaction. How can i cut the execution of code? Please help me guys.
#2

[eluser]noslen1[/eluser]
Did you try the Form_validation library with a custom validation rule ?
User guide's documentation here
#3

[eluser]jojo777[/eluser]
As noslen1 said use the Form_validation library and also you can include custom callbacks to the validation rules so you can control some data is what you want and if it pass the validation i'll be stored or whatever you want.

Ask if you have some questions about this




Theme © iAndrew 2016 - Forum software by © MyBB