Jump to content

Wordpress additional field during registration, how?


vinnier

Recommended Posts

Hi all!

 

I am looking for a way to have an extra filed during registration with my Wordpress 2..9.2 Mu. I have tried 2 plugins register pie and register plus and they don't work with the newest WP.

I have found this on WP forums:

 

 

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(){
?>

// 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>

// Last Name Fiels
<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');

}

?>

 

Question is how to adapt it to add one field which is not mandatory, sort of promo code if you have one type it in if not leave blank deal...

Or is there a better way?

 

Thanks in advance!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.