WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I´m trying to add first name, last name and company name to my custom registration page. The registration form almost works, but there is a problem.

So far I´ve got this code, but I cant get the first name, last name and company name registered. Can anyone help me out please?

<?php if(!is_user_logged_in()) { ?>

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



    //We shall SQL escape all inputs
    $username = $wpdb->escape($_REQUEST['username']);
    if(empty($username)) {
        echo "ERROR... please type username";
    $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 "ERROR... please valid email";
    $first_name = $wpdb->escape($_REQUEST['first_name']);
    if(empty($first_name)) {
        echo "ERROR... please add first name";
    $last_name = $wpdb->escape($_REQUEST['last_name']);
    if(empty($last_name)) {
        echo "ERROR... please add last name";
    $companyname = $wpdb->escape($_REQUEST['companyname']);
    if(empty($companyname)) {
        echo "ERROR... please add company name";

    $pass1 = $wpdb->escape($_REQUEST['pass1']);
$pass2 = $wpdb->escape($_REQUEST['pass2']);
if ($pass1 != $pass2){
    echo "ERROR... password's does'nt mach";

$random_password = $pass1;
    $status = wp_create_user( $username, $random_password, $email );
    if ( is_wp_error($status) )
        echo "ERROR... username allready exist's";
    else {
        $from = get_option('admin_email');
        $headers = 'Fra: '.$from . "\r\n";
        $subject = "Registreringen er fullført";
        $msg = "Hi, you are now registered. Here is your username and password:\n\n$username\n$random_password";
        wp_mail( $email, $subject, $msg, $headers );
        echo "Thank you for registering. You can now log inn.";


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


<div id="result"></div>

<form id="wp_signup_form" action="" method="post">

<strong>Username:</strong><br />
<input type="text" name="username" style="width:350px; margin-bottom:3px;"><br />

<strong>First name:</strong><br />
<input type="text" name="first_name" id="first_name" style="width:350px; margin-bottom:3px;"><br />

<strong>Last name:</strong><br />
<input type="text" name="last_name" id="last_name" style="width:350px; margin-bottom:3px;"><br />

<strong>Companyname:</strong><br />
<input type="text" name="companyname" id="companyname" style="width:350px; margin-bottom:3px;"><br />

<strong>E-mail</strong><br />
<input type="text" name="email" style="width:350px; margin-bottom:3px;"><br />

<strong>Password:</strong><br />
<input id="password" class="input" type="password" value="Passord" name="pass1" style="width:350px; margin-bottom:3px;" /><br />
<strong>Repeat password:</strong><br />
<input id="repeat_password" class="input" type="password" name="pass2" style="width:350px; margin-bottom:3px;" /><br />

<input type="submit" id="submitbtn" name="submit" value="Register" class="knapp" style="padding:8px;">
<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();
type: "POST",
url:  "<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>",
data: input_data,
success: function(msg){
return false;

// embedded




<!-- regskjema end -->
<br />
<?php } else { ?>
You are allready registered and logged inn. <a href="<?php bloginfo('url'); ?>/profilside">Click here</a> to load your profilepage.
<?php } ?>
share|improve this question

There's wp_login_form() for such cases. It offers tons of hooks to extend it.

// In your template
wp_login_form( array( /* Args: refer to Codex page */ ) );

A more in-depth look at the filters, can be found here @GitHub WP Core source.

  • 'login_form_top' - above login-username
  • 'login_form_middle' - above login-submit
  • 'login_form_bottom' - below login-submit

My personal suggestion is: Don't use an AJAX login form. It's hard to maintain, much easier to hack (in some cases) and will be a pain, when there're other parts on the page, that show logged-in/visitor information, as you'll have to maintain all your login forms on-the-fly UI updates with every change on the page.

If you still want to do the whole thing with AJAX, then I'd suggest to register an event listener/handler to id_submit (the arg that is used in the template tag above). There you can easily return false; or use event.preventDefault(); to disable the redirection and roll your own registration (copy core).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.