Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have added some extra fields like first_name,middle name,last_name etc into the custom registration form. I want to add those details int the DB also. Now only username,email,Display name and user_nice name are inserted into the db. How can i add the extra fields added in the front end to the DB?

Following is the template i used to create login/Register/Forgot page

<?php
/*
Template Name: Registration Template
*/
get_header();?>
<div id="login-register-password">

<?php global $user_ID, $user_identity; get_currentuserinfo(); if (!$user_ID) { ?>

<ul class="tabs_login">
    <li class="active_login"><a href="#tab1_login">Login</a></li>
    <li><a href="#tab2_login">Register</a></li>
    <li><a href="#tab3_login">Forgot?</a></li>
</ul>
<div class="tab_container_login">
    <div id="tab1_login" class="tab_content_login">

        <?php $register = $_GET['register']; $reset = $_GET['reset']; if ($register == true) { ?>

        <h3>Success!</h3>
        <p>Check your email for the password and then return to log in.</p>

        <?php } elseif ($reset == true) { ?>

        <h3>Success!</h3>
        <p>Check your email to reset your password.</p>

        <?php } else { ?>

        <?php } ?>

        <form method="post" action="<?php bloginfo('url') ?>/wp-login.php" class="wp-user-form">
            <div class="username">
                <label for="user_login"><?php _e('Username');_e("/");_e("Email"); ?>: </label>
                <input type="text" name="log" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="11" />
            </div>
            <div class="password">
                <label for="user_pass"><?php _e('Password'); ?>: </label>
                <input type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" />
            </div>
            <div class="login_fields">
                <div class="rememberme">
                    <label for="rememberme">
                        <input type="checkbox" name="rememberme" value="forever" checked="checked" id="rememberme" tabindex="13" /> Remember me
                    </label>
                </div>
                <?php do_action('login_form'); ?>
                <input type="submit" name="user-submit" value="<?php _e('Login'); ?>" tabindex="14" class="user-submit" />
                <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
                <input type="hidden" name="user-cookie" value="1" />
            </div>
        </form>
    </div>
    <div id="tab2_login" class="tab_content_login" style="display:none;">
        <h3>Sign Up</h3>
        <p>We encourage you to do a one-time signup with us to be able to download content from this website</p>
        <form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
            <div class="username">
                <label for="title"><?php _e('Title'); ?>: </label>
                <Select>
                    <option>Mr</option>
                    <option>Ms</option>
                    <option>Mrs</option>
                </select>
            </div>
            <div class="username">
                <label for="user_login"><?php _e('First Name'); ?>: </label>
                <input type="text" name="first_name" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="20" id="first_name" tabindex="101" required/>
            </div>
            <div class="username">
                <label for="user_login"><?php _e('Middle Name'); ?>: </label>
                <input type="text" name="middle_name" value="<?php echo esc_attr(stripslashes($middle_name)); ?>" size="20" id="middle_name" tabindex="101" />
            </div>
            <div class="username">
                <label for="user_login"><?php _e('Last Name'); ?>: </label>
                <input type="text" name="last_name" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="20" id="last_name" tabindex="101" required/>
            </div>
            <div class="username">
                <label for="user_login"><?php _e('Username'); ?>: </label>
                <input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_name)); ?>" size="20" id="user_login" tabindex="101" required />
            </div>
            <div class="password">

                <label for="user_email"><?php _e('Email Address'); ?>: </label>
                <input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" required/>
            </div>
            <div class="password">
                <label for="organisation"><?php _e('Organisation'); ?>: </label>
                <input type="text" name="organisation" value="<?php echo esc_attr(stripslashes($user_org)); ?>" size="25" id="organisation" tabindex="102" />
            </div>
            <div class="password">
                <label for="Designation"><?php _e('Designation'); ?>: </label>
                <input type="text" name="Designation" value="<?php echo esc_attr(stripslashes($user_desig)); ?>" size="25" id="designation" tabindex="102"/>
            </div>
            <div class="password">
                <label for="Designation"><?php _e('Which Product are you interested in'); ?>: </label>
                <Select>
                    <option>COREDC</option>
                    <option>COREAE</option>
                    <option>COREQROPS</option>
                    <option>CORE Point Solutions</option>
                    <option>Just Exploring</option>
                </select>
            </div>
            <div style="width:100px;position:relative;float:left;margin: 7px 0 0 0;">
                <input type="button" name="user-cancel" value="<?php _e('Cancel'); ?>" id="user-cancel" tabindex="103" />
            </div>
            <div class="login_fields">
                <?php do_action('register_form'); ?>
                <input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-signup" tabindex="103" />
                <?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
                <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?register=true" />
                <input type="hidden" name="user-cookie" value="1" />
            </div>
        </form>
    </div>
    <div id="tab3_login" class="tab_content_login" style="display:none;">
        <h3>Lose something?</h3>
        <p>Enter your username or email to reset your password.</p>
        <form method="post" action="<?php echo site_url('wp-login.php?action=lostpassword', 'login_post') ?>" class="wp-user-form">
            <div class="username">
                <label for="user_login" class="hide"><?php _e('Username or Email'); ?>: </label>
                <input type="text" name="user_login" value="" size="20" id="user_login" tabindex="1001" />
            </div>
            <div class="login_fields">
                <?php do_action('login_form', 'resetpass'); ?>
                <input type="submit" name="user-submit" value="<?php _e('Reset my password'); ?>" class="user-submit" tabindex="1002" />
                <?php $reset = $_GET['reset']; if($reset == true) { echo '<p>A message will be sent to your email address.</p>'; } ?>
                <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?reset=true" />
                <input type="hidden" name="user-cookie" value="1" />
            </div>
        </form>
    </div>
</div>

<?php } else { // is logged in ?>

<div class="sidebox">
    <h3>Welcome, <?php echo $user_identity; ?></h3>
    <div class="usericon">
        <?php global $userdata; get_currentuserinfo(); echo get_avatar($userdata->ID, 60); ?>

    </div>
    <div class="userinfo">
        <p>You&rsquo;re logged in as <strong><?php echo $user_identity; ?></strong></p>
        <p>
            <a href="<?php echo wp_logout_url('index.php'); ?>">Log out</a> | 
            <?php if (current_user_can('manage_options')) { 
                echo '<a href="' . admin_url() . '">' . __('Admin') . '</a>'; } else { 
                echo '<a href="' . admin_url() . 'profile.php">' . __('Profile') . '</a>'; } ?>
        </p>
    </div>
</div>

<?php } ?>

</div>

<?php get_footer(); ?>
share|improve this question
    
Please do not cross-post questions: stackoverflow.com/questions/15387127 See: meta.stackexchange.com/questions/64068 –  s_ha_dum Mar 13 '13 at 14:00
1  
There are timestamps on these questions. You waited maybe five minutes before cross-posting. Sorry, but "I'm not getting an answer here" is hard to swallow. You just didn't feel like waiting and posting them effectively simultaneously. –  s_ha_dum Mar 13 '13 at 14:08
add comment

3 Answers

Why the downvotes for using user meta? That's how I do it, I store all the extra profile stuff in wp_usermeta table by utilizing update_user_meta.

<?php

// first validate all $_POST data
$validated = $this->validate_and_sanitize();

$username = $validated['uname'];
$password = $validated['pass'];
$email = $validated['email'];

$new_user_id = wp_create_user($username, $password, $email);

if ( is_wp_error($new_user_id) && array_key_exists('existing_user_login', $new_user_id->errors)) {
    $return['status'] = 2; // email entered is already in use
    $return['msg'] = 'Email entered is already in use';
    echo json_encode($return);
    exit;
}
if( !is_wp_error($new_user_id) ) {
    if (isset( $validated['phone'] ) && strlen(trim($phone)) > 0) { 
        $phone = mysql_real_escape_string($validated['phone']);
        $umeta_id_phone = update_user_meta( $new_user_id, 'phone', $phone ); 
    }
    if (isset( $validated['phone'] ) && strlen(trim($city)) > 0) {
        $city = mysql_real_escape_string($validated['city']);
        $umeta_id_city = update_user_meta( $new_user_id, 'city', $city ); 
    }
}
share|improve this answer
    
"Why the downvotes for using user meta?". Why are you asking? Add your upvote to the other answer and it's fine. –  kaiser Mar 13 '13 at 18:57
    
Where shall I put this code? In my template file?? –  MidhuN Mar 14 '13 at 6:01
    
You can, but in my case it's inside a plugin because this functionality should not be theme-dependent. –  dalbaeb Mar 14 '13 at 15:50
add comment

You can add extra fields on (user meta tables) using this function add_user_meta() and also can delete_user_meta(), get_user_meta(), update_user_meta().

share|improve this answer
add comment

You need to save those to usermeta table with key,value pair..

share|improve this answer
1  
Might you take yourself a minute and consider explaining the how and why? I consider adding my upvote as well. Or an upvote in case the edit makes it better. –  kaiser Mar 13 '13 at 18:56
add comment

Your Answer

 
discard

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.