I have a form that redirects to a payment platform and sends data in $_POST.
<form method="POST" action=".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);
I have a form that redirects to a payment platform and sends data in $_POST.
<form method="POST" action="https://www.paiementgateway/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);
Share
Improve this question
asked Apr 15, 2020 at 17:41
KamdurasKamduras
11 bronze badge
2 Answers
Reset to default 0That'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.
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/paiement/order1.pl?', 307 );
exit;
}
}
add_action('template_redirect', 'traitement_formulaire_inscription', 5);