简体   繁体   English

用户根据单选按钮wordpress注册后如何重定向

[英]How to redirect after user register according to radio button wordpress

I am trying to redirect page after user registers i created two radio button paynow and pay later in user register i want to redirect when the user clicks paynow user should register and redirect to custom url and if the user select pay later user should register and send custom url to user for future payment here is the code i used 我尝试在用户注册后重定向页面,我创建了两个单选按钮paynow,并稍后在用户注册中付款。我想在用户单击paynow时进行重定向,用户应注册并重定向到自定义网址,如果用户选择以后付款,则用户应注册并发送自定义网址以供用户将来付款,这是我使用的代码

    $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'] ) );
        }


    }

?> 

You can redirect the user through JavaScript depending on the $_POST value of your radio: 您可以通过JavaScript重定向用户,具体取决于收音机的$ _POST值:

// 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;

And on the frontend, create a form with the radios: 在前端,用收音机创建一个表单:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM