I have a problem. I have a credit card form, where the customer will fill out the data and be submitted to the bank's evaluation. However, it should perform some operations \*\* before \*\* of the function that will send its data to the payment gateway.
I will illustrate a step by step of what should be happening:

1. User fills card details;
2. Send the form;
3. User receive the response "Please wait, reviewing data";
4. User received a "Payment approved" or "Payment denied" response;

But step 3 is not running. Here is my code:

```
$('#credit_card_form').submit(function() {
    $.post($("#credit_card_form").attr('action'), $("#credit_card_form").serialize(), function(data){
        $("#return_form").html(data);
    }); 
    return false;
});

```

The POST is sent to here:

```
if ($_POST['f'] == 'pay_credit_card') {
    $brand_card = $_POST['card_brand'];
    $number_card = $_POST['card_number'];
    $exp_month = $_POST['card_valid_month'];
    $exp_year = $_POST['card_valid_year'];
    $cod_security = $_POST['card_security'];
    $name_card = $_POST['card_name'];

    // Example - just to illustrate that i have a check here
    if ($_POST['card_number'] == '') {
        echo "Fill the field X"
        return false;
    }

    // d_none = display: none;
    echo "<script>$('#processing_card').removeClass('d_none'); $('#div_credit_card_form').addClass('d_none');</script>";
    $return_gateway = CS_MundiPagg($brand_card, $number_card, $exp_month, $exp_year, $cod_security, $name_card);
    if ($return_gateway == 'Captured') {        
        echo "<script>$('#success_card').removeClass('d_none'); $('#modal-close').addClass('d_none');</script>";
    }
}

```

The script goes through "echo" above of CS\_MundiPagg() and goes straight to the answer, at the end of the script. As if it "crashes" the script after the user submits the form and bring only the final answer (payment approved or not).

I've tried almost everything, I'm not finding a solution. Is there hope at the end of the tunnel?