Custom wordpress Register page redirect to 404 page not found when click on submit button

how to code custom submit form in php in wordpress
wordpress page not found
wordpress preview not working 404
wordpress update page not found
wordpress page not found but it exists
wordpress page not found after publish
wordpress home page not found
wordpress plugin form submit action

am creating my custom wordpress theme register page , but some reason i don't understand when i click on submit when the fields are filled it will redirect me to my 404 , but when i click on it when i have not filled any field , it will sent me the message error. Here is my code

 <?php
    the_post();
    $err = '';
    $success = '';

    global $wpdb, $PasswordHash, $current_user, $user_ID;

    if('POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) &&  $_POST['action'] == "submit-a-plate" ) {

        var_dump($_POST);



        $name = $wpdb->escape(trim($_POST['name']));
        $pwd = $wpdb->escape(trim($_POST['password']));
        $name = $wpdb->escape(trim($_POST['name']));
        $username = $wpdb->escape(trim($_POST['user_name']));
        $email = $wpdb->escape(trim($_POST['email']));
        $phone = $wpdb->escape(trim($_POST['phone']));
        $school = $wpdb->escape(trim($_POST['school']));
        $role = $wpdb->escape(trim($_POST['role']));
        $level = $wpdb->escape(trim($_POST['level']));



        if( $name == "" || $pwd == "" || $name == "" || $username == "" || $email == "" || $phone == "" || $school == "" || $role == "" || $phone == "") {
            $err = 'Please don\'t leave fill all the fields.';
        } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $err = 'Invalid email address.';

        } else if(email_exists($email) ) {
            $err = 'Email already exist.';
        } else {
            var_dump($email);
            die();


            $user_id = wp_insert_user( array ('first_name' => apply_filters('pre_user_first_name', $first_name), 'last_name' => apply_filters('pre_user_last_name', $last_name), 'user_pass' => apply_filters('pre_user_user_pass', $pwd1), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'subscriber' ) );

            if( is_wp_error($user_id) ) {
                $err = 'Error on user creation.';
            } else {
                do_action('user_register', 'add_user_extra_info');

                function add_user_extra_info($user_id){

                    $metas = array( 
                        'phone'   => $phone,
                        'level' => $level, 
                        'role'  => $role ,
                        'name'       => $name ,
                        'school'     => $school
                    );
                    foreach($metas as $key => $value) {
                        update_user_meta( $user_id, $key, $value );
                    }

                }

                $success = 'You\'re successfully register';
            }

        }
    }



?>


enter code here

<form  method="post" > 

                <div class="field">
                  <label class="label">Name</label>
                  <div class="control has-icons-left">
                    <input name="name" class="input has-icons-left" type="text" placeholder="Text input">
                    <span class="icon is-small is-left">
                      <i class="fas fa-user"></i>
                    </span>
                  </div>
                </div>

                <div class="field">
                  <label class="label">Username</label>
                  <div class="control has-icons-left ">
                    <input name="user_name" class="input " type="text" placeholder="Text input" >
                    <span class="icon is-small is-left">
                      <i class="fas fa-user"></i>
                    </span>

                  </div>
                </div>

                <div class="field">
                  <label class="label">Email</label>
                  <div class="control has-icons-left ">
                    <input name="email" class="input " type="email" placeholder="Email input" >
                    <span class="icon is-small is-left">
                      <i class="fas fa-envelope"></i>
                    </span>

                  </div>

                </div>

                <div class="field">
                  <label class="label">Phone</label>
                  <div class="control has-icons-left ">
                    <input name="phone" class="input " type="number" placeholder="" >
                    <span class="icon is-small is-left">
                      <i class="fas fa-mobile-alt"></i>
                    </span>

                  </div>

                </div>
                 <div class="field">
                  <label class="label">School</label>
                  <div class="control has-icons-left ">
                    <input name="school" class="input " type="text" placeholder="" >
                    <span class="icon is-small is-left">
                      <i class="fas fa-mobile-alt"></i>
                    </span>

                  </div>

                </div>



                <div class="field">
                  <label class="label">Password</label>
                  <div class="control has-icons-left ">
                    <input name="password" class="input " type="password" >
                    <span class="icon is-small is-left">
                      <i class="fas fa-lock"></i>
                    </span>

                  </div>

                </div>

                <div class="field">
                  <label class="label">Role</label>
                  <div class="control">
                    <div class="select">
                      <select name="role">
                        <option value="Teacher">Teacher</option>
                        <option value="Student">Students</option>
                        <option value="Book author">Book author</option>
                        <option value="Others">Others</option>
                      </select>
                    </div>
                  </div>
                </div>

                <div class="field">
                  <label class="label">Level</label>
                  <div class="control">
                    <div class="select">
                      <select name="level">
                        <option value="o level">O level </option>
                        <option value="a level">A level</option>

                        <option value="others">Others</option>
                      </select>
                    </div>
                  </div>
                </div>


                <div class="field">
                  <div class="control">
                    <label class="checkbox">
                      <input type="checkbox">
                      I agree to the <a href="#">terms and conditions</a>
                    </label>
                  </div>
                </div>



                <div class="field is-grouped">
                  <div class="control">
                    <input type="submit" name="btnregister" class="input is-medium button submits is-rounded" value="Register" />
                       <input type="hidden" name="action" value="submit-a-plate" />

                  </div>

                </div>

                </form>
              </div>
            </div>

sorry my code :) is abit long

Not an expert and new to stackoverflow, but I wonder why you use do_action and a function at this point in your code:

do_action('user_register', 'add_user_extra_info');

            function add_user_extra_info($user_id){

                $metas = array( 
                    'phone'   => $phone,
                    'level' => $level, 
                    'role'  => $role ,
                    'name'       => $name ,
                    'school'     => $school
                );
                foreach($metas as $key => $value) {
                    update_user_meta( $user_id, $key, $value );
                }

            }

Perhaps change it to:

                $metas = array( 
                    'phone'   => $phone,
                    'level' => $level, 
                    'role'  => $role ,
                    'name'       => $name ,
                    'school'     => $school
                );
                foreach($metas as $key => $value) {
                    update_user_meta( $user_id, $key, $value );
                }

           $success = 'You\'re successfully register';

The function you create only passes $user_id and not the other variables like $phone, etc. No point using a function here :)

Solved & Fixed: WordPress displaying 404 page on POST form , Easily fix WordPress POST and REQUEST 404 error on form submission. Tweet or ensure that the variables we use are not reserved by WordPress? <form comments_popup; custom; customize_messenger_channel; customized; cpage. Setting up a 404 Page. WordPress makes it really simple to create your basic 404 page. Essentially, it routes all pages that aren’t found to a 404.php file in your theme directory. So, if you create a file called 404.php, you’ve already set up your 404 page.

For does who may have the same problem , here is the solution , there is a collision with the variable name $name and $user_name with cause the redirect , i just changed it and all works fine.

Custom wordpress Register page redirect to 404 page not found , Not an expert and new to stackoverflow, but I wonder why you use do_action and a function at this point in your code: do_action('user_register'  In this article we will show you how to fix WordPress posts returning 404 error. Usually in this scenario a user can access their WordPress admin area, their blog’s main page, but when accessing a single posts they get a 404 Not found error. First of all, don’t panic most of the time your posts are still there and completely safe.

Form action must be $_SERVER['REQUEST_URI'] then you will get post data on same page.

Contact Form 7 redirect to 404 not found page when creating a new , [This thread is closed.] Hi, When I try to make a new form ( or even duplicate the standard and save with new name ) I got redirected to a 404 not… Settings - Settings page of 404 to 301. Error Logs - Logged 404 Errors. Custom Redirect - Setting custom redirect for each 404 paths. Installatie. Installing the plugin – Simple. In your WordPress admin panel, go to Plugins > New Plugin, search for 404 to 301 and click “ Install now “.

Submitting a form in WordPress redirects to 404 page, How to fix a bug on a WordPress website's contact form whereby submitting the form redirects to a 404 not found page. Try to look for a page that does not exist on your website. You should get your custom 404 page that you denoted in the .htaccess file. Step 6: Did it work? If not, update the settings of your

How to Fix Error 404 Not Found on Your WordPress Site, Encountering the Error 404 Not Found message on your WordPress site? and you can create your own custom 404 page to help get visitors to the right To add a new redirect, click the large “Add Redirect Rule” button:. set the redirect type (default is 301 – permanent, but you can do temporary etc) it also allows you to redirect to posts/pages without knowing the URL. it is also useful for redirecting 404/page not founds as it does not requiring an existing page/post (although most are like that) If you want more complex functionality than either of these

How to Fix 404 Error on WordPress Posts and Pages (3 Methods), Fix 404 errors in WordPress easily by resetting your permalinks, .htaccess file, can be quite vague, any website can set up its own custom 404 error page. In some cases, WordPress page not found errors soon disappear on their own. Settings, and click on the Save button at the bottom of the page:. The reasons for this can be varied. Advisable to try rebuilding permalinks, rebuilding httaccess rules and/or checking for plugin conflict. Your host should also be able to advise of any server level issues – but the problem is rarely ever related to the theme.

Comments
  • hello @Vos i corrected it but am still having the same error and idea ?