dqpdb82600 2017-04-23 13:22
浏览 79
已采纳

Wordpress注册创建页面未找到即将提交表单

I have created a function to create a login registration form custom but I do not why when i click on submit for it is showing me 404 not found error i do not know why this is happening

unction registration_form( $name, $fname, $email, $password, $familyname, $username,  $password, $gender) {

echo '
<div class="login-form">
<form action="' . get_site_url() . '/sign-up" method="post">
<div class="form-group">
<input type="text" name="name" placeholder="Name" value="' . ( isset( $_POST['name'] ) ? $name : null ) . '">
</div>

<div class="form-group">
<input type="text" name="fname" placeholder="Father Name" value="' . ( isset( $_POST['fname']) ? $fname : null ) . '">
</div>

<div class="form-group">
<input type="text" name="familyname" placeholder="Family Name" value="' . ( isset( $_POST['familyname']) ? $familyname : null ) . '">
</div>

<div class="form-group">
<input type="text" name="email" placeholder="Email" value="' . ( isset( $_POST['email']) ? $email : null ) . '">
</div>

<div class="form-group">
<input type="text" name="username" placeholder="Username" value="' . ( isset( $_POST['username']) ? $username : null ) . '">
</div>

<div class="form-group">
<input type="password" name="password" placeholder="Password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '">
</div>

<div class="form-group">
    <label for="nickname">Gender</label>
    <div><input type="radio" name="gender" value="Male"> Male</div> 
    <div><input type="radio" name="gender" value="Female"> Female</div> 
</div>

<input type="submit" name="submit" value="Register"/>

<div class="form-group"><br>
Already have account with us <a href="'.get_site_url().'/log-in" title="" class="reg" id="">Login Here</a>
</div>

</form>
</div>
';
 }

function complete_registration() {
global $name, $fname, $password, $familyname, $username,  $password, $gender;
if ( 1 > count( $reg_errors->get_error_messages() ) ) {
    $userdata = array(
    'user_login'    =>   $username,
    'user_email'    =>   $email,
    'user_pass'     =>   $password,
    'user_name'     =>   $name,
    'family_name'   =>   $familyname,
    'father_name'   =>   $fname,
    'gender'        =>   $gender
    );
    $user = wp_insert_user( $userdata );
    echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';   
}

}

function custom_registration_function() {
if ( isset($_POST['submit'] ) ) {
    // sanitize user form input
    $username   =   sanitize_user( $_POST['username'] );
    $password   =   esc_attr( $_POST['password'] );
    $email      =   sanitize_email( $_POST['email'] );
    $name       =   esc_url( $_POST['name'] );
    $fname      =   sanitize_text_field( $_POST['fname'] );
    $familyname =   sanitize_text_field( $_POST['familyname'] );
    $gender     =   sanitize_text_field( $_POST['gender'] );

    // call @function complete_registration to create the user
    // only when no WP_error is found
    complete_registration(
        $username,
        $password,
        $email,
        $name,
        $fname,
        $familyname,
        $gender
    );
} else {
     registration_form(
       $username,
        $password,
        $email,
        $name,
        $fname,
        $familyname,
        $gender
    );
}

}

// Register a new shortcode: [cr_custom_registration]
add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );

// The callback function that will replace [book]
function custom_registration_shortcode() {
    ob_start();
    custom_registration_function();
    return ob_get_clean();
}

Above is the code I have created but when I click on submit it shows me 404 not found as it shoudn't be The link given in the action is same so i do not know why this is happening

  • 写回答

1条回答 默认 最新

  • douzhuiqing1151 2017-04-23 15:27
    关注

    You get a 404 because your form action is "sign-up" and I assume that you didn't create such an url. You need to create a page template that displays your custom form and assign it to a page which has the "sign-up" slug. Or you can create a virtual page, where you should process your form.

    Details on how to create a virtual page in wordpress here: https://wordpress.stackexchange.com/questions/9870/how-do-you-create-a-virtual-page-in-wordpress

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作