WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] HOWTO: Custom Registration Fields (6 posts)

  1. westondeboer
    Member
    Posted 4 years ago #

    This can be put into functions.php this is simple as it can be

    <?php
    
    // This function shows the form fiend on registration page
    add_action('register_form','show_first_name_field');
    
    // This is a check to see if you want to make a field required
    add_action('register_post','check_fields',10,3);
    
    // This inserts the data
    add_action('user_register', 'register_extra_fields');
    
    // This is the forms The Two forms that will be added to the wp register page
    function show_first_name_field(){
    ?>
    
    <p>
    <label>First Name<br />
    <input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['first']; ?>" name="first"/>
    </label>
    </p>
    
    <p>
    <label>Last Name<br />
    <input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['last']; ?>" name="last"/>
    </label>
    </p>
    <?php
    }
    
    // This function checks to see if they didn't enter them
    // If no first name or last name display Error
    function check_fields($login, $email, $errors) {
    	global $firstname, $lastname;
    	if ($_POST['first'] == '') {
    		$errors->add('empty_realname', "<strong>ERROR</strong>: Please Enter in First Name");
    	} else {
    		$firstname = $_POST['first'];
    	}
    	if ($_POST['last'] == '') {
    		$errors->add('empty_realname', "<strong>ERROR</strong>: Please Enter in Last Name");
    	} else {
    		$firstname = $_POST['last'];
    	}
    }
    
    // This is where the magiv happens
    function register_extra_fields($user_id, $password="", $meta=array())  {
    
    // Gotta put all the info into an array
    $userdata = array();
    $userdata['ID'] = $user_id;
    
    // First name
    $userdata['first_name'] = $_POST['first'];
    
    // Last Name
    $userdata['last_name'] = $_POST['last'];
    
    // Enters into DB
    wp_update_user($userdata);
    
    // This is for custom meta data "gender" is the custom key and M is the value
    // update_usermeta($user_id, 'gender','M');
    
    }
    
    ?>

    I will be posting more at:
    http://tipsforwordpress.com/wordpress/add-custom-field-to-register-form/

    [[moderated fixed code ]

  2. plz.help.me
    Member
    Posted 4 years ago #

    Nice

  3. wojtekor
    Member
    Posted 4 years ago #

    How do I add just one extra field during registration? I want it to be optional, sort of promotional code insert if you have one.
    I have tried Pie Register and Register Plus, non of which works with my 2.9.2 mu... Help ;(

  4. wojtekor
    Member
    Posted 4 years ago #

    help anyone?

  5. Paul de Wouters
    Human Made
    Posted 3 years ago #

    thanks, this is exactly what I needed

  6. mdevaney
    Member
    Posted 3 years ago #

    any idea how to make that info post to a page, instead of first name and last name... having title and content? and on submit, it automatically posts?

Topic Closed

This topic has been closed to new replies.

About this Topic