PHP Form in Wordpress - Button not redirect nor reload



I'm trying to redirect (or reload) a page after a successful registration on the modal popup form. The data is sending correct to the database after the user click the button but the redirection/reload isn't working. Maybe I need to use Ajax but I have no clue how to do that.

What I've tried so far in the button:

  • onclick='window.location.reload(true); // Reload the page but doesn't send the data
  • onclick="location.reload();" // Reload the page but doesn't send the data
  • onClick="history.go(0);" // Send the data but doesn't reload the page
  • action="<?php echo $_SERVER['PHP_SELF']; ?>" // Send the data but doesn't reload

What I've tried so far in the loop, after do_action:

  • wp_redirect(home_url()); exit(); // no changes
  • wp_redirect( $url;) // no changes

Here is the php form:

$user_input = array(
            'user_login'    =>  $_POST['username'],
            'display_name'  =>  $_POST['username'],
            'user_email'    =>  $_POST['email'],
            'first_name'    =>  $_POST['fname'],
            'last_name'    =>  $_POST['lname'],
            'native_language'    =>  $_POST['phone'],
            'user_pass'     =>  $_POST['password']
        );
        $user_id = wp_insert_user( $user_input );
        
        update_user_meta( $user_id,'phone_number',$_POST['phone'] );

    
        if (!is_wp_error($user_id)) {
            wp_set_current_user( $user_id, $username );
            wp_set_auth_cookie( $user_id );
            do_action('loggedin', $username );
            die();
            
        } else {
        echo $user_id->get_error_message();
                }

        }

Here is the button:

    <button class="docent_btn btn-fill register_button" type="submit" style="width:100%">
    <?php esc_html_e('Register', 'docent-pro-core');?></button><?php wp_nonce_field( 'ajax-register-nonce', 'security' ); ?>

Thanks for the help!