• Hi folks i’ve created a function to redirect the submitted form to my paiement provider for online payment. with the “wpcf7_before_send_mail” action.

    The function is working well except that i need to deactivate javascript for the form otherwise my submit button is not working.

    here is the code of my function:
    <?php

    add_action('wpcf7_before_send_mail', 'wpcf7_1redirectPostfinance');
    function wpcf7_1redirectPostfinance ($cf7 ) {
    $form_id = $cf7->id();
    // apply redirection to pf from the following cf7 form ids
    if ($form_id == 13570 || $form_id == 9483 || $form_id == 2201):
    $submission = WPCF7_Submission::get_instance();
    if ( $submission ) {
    $formdata = $submission->get_posted_data();
    }
    $my_current_lang = apply_filters( 'wpml_current_language', NULL );
    if ($my_current_lang == 'fr') {
    $lang='fr_FR';
    } elseif ($my_current_lang == 'de') {
    $lang='de_DE';
    } elseif ($my_current_lang == 'it') {
    $lang='it_IT';
    } else {$lang='de_DE';}

    // Form data to send to postfinance (ogone)
    $form = array(
    'PSPID' => 'my_psp_id',
    'ORDERID' => $formdata['refenfant'].' '.$formdata['menu-306'],
    'AMOUNT' => $formdata['wert']*100,
    'CURRENCY' => 'CHF',
    'LANGUAGE' => $lang,
    'CN' => $formdata['vorname'].' '.$formdata['nachname'],
    'EMAIL' => $formdata['email'],
    'ACCEPTURL' => 'my accept url',
    'DECLINEURL' => 'my decline url',
    'EXCEPTIONURL' => 'my exeption url',
    'CANCELURL' => 'my cancel url',
    );
    //generate hash string
    $arrayToHash = array();
    foreach ($form as $key => $value) {
    if ($value != '' ) {
    $arrayToHash[] = strtoupper($key) . '=' . $value . 'my hash value';
    }
    }
    asort($arrayToHash);
    $stringToHash = implode('', $arrayToHash);
    $hashedString = sha1($stringToHash);

    ?>
    //send the form to postfinance
    <html>
    <head><title>Redirecting to Postfinance...</title></head>
    <body>
    <form action='https://e-payment.postfinance.ch/ncol/test/orderstandard.asp' method='post' name="pf_for_contact_form">
    <input type="hidden" name="PSPID" value="<?php echo $form['PSPID']; ?>">
    <input type="hidden" name="ORDERID" value="<?php echo $form['ORDERID']; ?>">
    <input type="hidden" name="AMOUNT" value="<?php echo $form['AMOUNT']; ?>">
    <input type="hidden" name="CURRENCY" value="<?php echo $form['CURRENCY']; ?>">
    <input type="hidden" name="LANGUAGE" value="<?php echo $form['LANGUAGE']; ?>">
    <input type="hidden" name="CN" value="<?php echo $form['CN']; ?>">
    <input type="hidden" name="EMAIL" value="<?php echo $form['EMAIL']; ?>">
    <input type="hidden" name="ACCEPTURL" value="<?php echo $form['ACCEPTURL']; ?>">
    <input type="hidden" name="DECLINEURL" value="<?php echo $form['DECLINEURL']; ?>">
    <input type="hidden" name="EXCEPTIONURL" value="<?php echo $form['EXCEPTIONURL']; ?>">
    <input type="hidden" name="CANCELURL" value="<?php echo $form['CANCELURL']; ?>">
    <input type="hidden" name="SHASIGN" value="<?php echo $hashedString; ?>">
    </form>
    Form ID: <?php echo $form_id; ?>
    <script type="text/javascript">
    document.pf_for_contact_form.submit();
    </script>
    </body>
    </html>
    <?php
    endif;
    }

    ?>

    [ No bumping please. ]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘javascript and wpcf7_before_send_mail action’ is closed to new replies.