0

I have a form that redirects to a payment platform and sends data in $_POST.

<form method="POST" action="https://www.paiementgateway.com/paiement/order1.pl" accept-charset="UTF8" id="knp-form" target="_top">
        <table border="0" cellpadding="2" cellspacing="0" width="20%">
        <meta charset="UTF-8">
        <tr>
            <td width="50%">Nom:</td>
            <td width="50%"><input type="text" name="NOM" size="24" value=""></td>
        </tr>
        <tr>
            <td width="50%">Prenom:</td>
            <td width="50%"><input type="text" name="PRENOM" size="24" value=""></td>
        </tr>
        <tr>
            <td width="50%">Adresse:</td>
            <td width="50%"><input type="text" name="ADRESSE" size="24" value=""></td>
        </tr>
        <tr>
            <td width="50%">Code Postal:</td>
            <td width="50%"><input type="text" name="CODEPOSTAL" size="24" value=""></td>
        </tr>
        <tr>
            <td width="50%">Ville:</td>
            <td width="50%"><input type="text" name="VILLE" size="24" value=""></td>
        </tr>
        <tr>
            <td width="50%">Pays:</td>
            <td width="50%"><select size="1" name="PAYS">
            <option value="CH" selected="selected">Suisse </option>
            <option value="FR">France</option>
        </select>
        </td>
        </tr>
        <tr>
            <td width="50%">Tel:</font></td>
            <td width="50%"><input type="text" name="TEL" size="24" value=""></td>
        </tr>
        <tr>
            <td width="50%">E-mail:</font></td>
            <td width="50%"><input type="text" name="EMAIL" size="24" value=""></td>
        </tr>
        <input type="hidden" name="ID" value="1234567890">
        <input type="hidden" name="ABONNEMENT" value="123ABC465DEF7890">
        <tr>
        <td width="100%" colspan="2">
        <p align="center"><input type="submit" value="Envoyer" name="B1"></p></td>
        </tr>
        </table>

I wanted to create an action like a user registration but unfortunately the action doesn't seem to work.

The user is redirected to the payment platform without the user being created on WP.

function traitement_formulaire_inscription() {

    if (isset($_POST['B1']))  {

        $user_login = sanitize_text_field( $_POST['EMAIL'] );
        $user_email = sanitize_email( $_POST['EMAIL'] );
        $user = register_new_user( $user_login, $user_email );

    }
}
add_action('template_redirect', 'traitement_formulaire_inscription', 5);
0

That's because you're using a post action which sends the user to another website. The template_redirect never runs because the user isn't on your site any more. You'll need to keep them on the site, register the new user then send them to the gateway with the post data.

| improve this answer | |
  • Thank you for your answer, I have no idea how to proceed. The problem with wp_redirect is that I have the impression that you can't pass data to $_POST ... Only to $_GET. – Kamduras Apr 15 at 19:08
  • Do a search for either php or wp redirect with post. There's lots of answers here and on stack overflow about how to redirect to a url and send post data. There's lots of different methods. What you need to do is to not post to that url and instead, just check to see if the post B1 exists, register the user then do a redirect with post to the gateway. – uPrompt Apr 15 at 23:53
0

I found the solution.

I removed the action in form

<form method="POST" action="" accept-charset="UTF8" id="knp-form" target="_top">

And now the action hook with wp_redirect with 307 code.

function traitement_formulaire_inscription() {

    if (isset($_POST['B1']))  {

        $user_login = sanitize_text_field( $_POST['EMAIL'] );
        $user_email = sanitize_email( $_POST['EMAIL'] );
        $user = register_new_user( $user_login, $user_email );

        wp_redirect( 'https://www.paiementgateway.com/paiement/order1.pl?', 307 );
        exit;

    }
}
add_action('template_redirect', 'traitement_formulaire_inscription', 5);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.