Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:19:05+00:00 2026-06-18T01:19:05+00:00

I am working on a site where I have a frontend registration form and

  • 0

I am working on a site where I have a frontend registration form and it works as it should but now I am having difficulty with automatic login and redirect upon successful registration. I’ve tried a few plugins and codes in my themes functions file but none seem to work. So how can I automatically log a person in after a successful registration? Any help would be appreciated thanks.

<?php
if(get_option('users_can_register')) {
//Check whether user registration is enabled by the administrator
?>

<?php

if($_POST){
    //We shall SQL escape all inputs
    $username = $wpdb->escape($_REQUEST['username']);
    if(empty($username)) {
        echo "<span style='color:#FF0000'><strong>Error..</strong></span><br /><br />You have to fill in the username.";
        exit();
    }
    $email = $wpdb->escape($_REQUEST['email']);
    if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email)) {
        echo "<span style='color:#FF0000'><strong>Error..</strong></span><br /><br />please use a calid e-mailadress.";
        exit();
    }

    $pass1 = $wpdb->escape($_REQUEST['pass1']);
$pass2 = $wpdb->escape($_REQUEST['pass2']);
if ($pass1 != $pass2){
    echo "<span style='color:#FF0000'><strong>Error..</strong></span><br /><br />please use a passwords don't match.";
        exit();

}
$random_password = $pass1;
    $status = wp_create_user( $username, $random_password, $email );
    if ( is_wp_error($status) )
        echo "<span style='color:#FF0000'><strong>Feil..</strong></span><br /><br />Username allready exist. please try another one.";
    else {
        $from = get_option('admin_email');
        $headers = 'From: '.$from . "\r\n";
        $subject = "Registration ok!";
        $msg = "Welcome, you are now registered. Here is your username and password.\Info:\Username: $username\Password: $random_password";
        wp_mail( $email, $subject, $msg, $headers );
        echo "<strong>You are now registered. An e-mail is now sent to you with your username and password..";
    }

    exit();

}
 else
{
//Embed the register form and javascript here

?>


<div id="result"></div>
<div style="padding-top:5px;"><h2 style="font-size:16px;color:#06f;">Register</h2></div>

<form id="wp_signup_form" action="" method="post">
<p><label>Username<br />
<input type="text" name="username" style="width:250px; margin-bottom:3px;"></label></p>
<p><label>E-Mail<br />
<input type="text" name="email" style="width:250px; margin-bottom:3px;"></label></p>
<p><label>Password<br />
<input type="password" name="pass1" style="width:250px; margin-bottom:3px;"></label></p>
<p><label>Repeat Password<br />
<input type="password" name="pass2" style="width:250px; margin-bottom:3px;"></label></p>
<br />
<input type=checkbox name="termsnp">By registering I agree to the terms and policy<br /><br />
<input type="submit" id="submitbtn" name="submit" value="Register" class="knapp" style="padding:8px;">
</form>
<script type="text/javascript">                         
$("#submitbtn").click(function() {
$('#result').html('<img src="<?php bloginfo('template_url'); ?>/images/loader.gif" class="loader" />').fadeIn();
var input_data = $('#wp_signup_form').serialize();
$.ajax({
type: "POST",
url:  "<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>",
data: input_data,
success: function(msg){
$('.loader').remove();
$('
<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
}
});
return false;

});
</script>
<?php
// embedded

}
?>

<?php
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:19:07+00:00Added an answer on June 18, 2026 at 1:19 am

    I did not find out the correcting coding to use so what I ended up doing was using the plugin Formidable Pro to create a registration form which logs in and redirects upon successful registration. – http://formidablepro.com/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a site for about a week now and we
I have a site setup that is working fine in ie8 and firefox but
I have my site working perfectly in IE 6+ but it looks weird in
I am using Wordpress for the site and have added a user registration form
I have a contact form on site which used to work, but since last
I have site I am working on and the images take forever to load,
I am working on a site where I have an accordian control for the
I have to make some mods to an existing (and working) magento site. So
I have been working on a site that relies heavily on images, and so
I am working on a WordPress site and I have placed the following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.