我试图在用户注册后重定向页面。我在用户注册中创建了两个单选按钮paynow和paylater。我想在用户点击paynow时重定向。用户应该注册并重定向到自定义url。如果用户选择paylater,用户应该注册和发送自定义url给用户以备将来付款。这是我使用的代码
$myemail=$_POST['email'];
$first_name="firstname";
$last_name="lastname";
echo "<script>window.location.href='https://www.payumoney.com/?firstname=$first_name&last_name=$last_name'&email=$myemail'</script>";
$to="test@gmail.com";
$message = "
Please payus for registering account https://www.payumoney.com/?firstname=$first_name&last_name=$last_name'&email=$email'
";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
// Additional headers
$headers .= 'To: madu<test@gmail.com>' . "'r'n";
$headers .= 'From: madu<test@gmail.com>' . "'r'n";
// Mail it
mail($to, $subject, $message, $headers);
}
}
add_filter( 'registration_redirect', 'wpse_19692_registration_redirect' );
Radio buttons
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {
$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
?>
<p>
<input type="radio" name="paystatus" id="paystatus" value="paynow">Pay Now<br>
<input type="radio" name="paystatus" id="paystatus" value="paylater">Pay Later
</p>
<?php
}
//2. Add validation. In this case, we make sure first_name is required.
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
$errors->add( 'first_name_error', __( '<strong>ERROR</strong>: You must include a first name.', 'mydomain' ) );
}
return $errors;
}
//3. Finally, save our extra registration user meta.
add_action( 'user_register', 'myplugin_user_register' );
function myplugin_user_register( $user_id ) {
if ( ! empty( $_POST['paystatus'] ) ) {
$checkme= update_user_meta( $user_id, 'paystatus', trim( $_POST['paystatus'] ) );
}
}
?>
您可以根据收音机的$_POST值通过JavaScript重定向用户:
// example radio name: "payment_time"
// redirect to this url if value equals to "pay_now"
if(isset($_POST['payment_time']) && $_POST['payment_time'] == 'pay_now'):
?>
<script type="text/javascript">
window.location.href = "http://url1.com";
</script>
<?php elseif(isset($_POST['payment_time']) && $_POST['payment_time'] == 'pay_later'): ?>
<script type="text/javascript">
window.location.href = "http://url2.com";
</script>
<?php
endif;
在前端,用无线电创建一个表单:
<input type="radio" id="pay_now" name="payment_time" value="pay_now"><label for="pay_now"> Pay now</label>
<input type="radio" id="pay_later" name="payment_time" value="pay_later"><label for="pay_later"> Pay later</label>