Is it possible to add a required field when users sign up?

We need to collect extra information from people who sign-up to our site. Ideally, this should be a required field on this form which we can then look-up in the WordPress backend. Is this possible and, if so, how do we go about it?

Thanks.

  • Patrick

    Hi there @martin

    Welcome to the forums, glad to have you aboard!

    Currently, the recommended way to add additional registration fields is by using BuddyPress, as the Membership plugin is fully integrated with BuddyPress registration.

    Aside from all the cool community features you can use with BuddyPress, one the biggest advantages is the ability to turn off any components you do not need. So if you would use it just to enhance the registration form, all you would need is the Extended Profiles component to enable the x-profile fields where you can add your own.

    We are working on a major update to the Membership plugin which will have a boatload of new features including the ability to customize the registration form. But that new version is nowhere near release (or even beta for that matter).

  • martin

    Hi Patrick,

    Thanks for your reply. Unfortunately, we have tried Buddy Press but it seems to cause problems with our site the way it is set up. We just need a single extra field added and none of the extra features at this stage. After further searching we have found this post...

    https://premium.wpmudev.org/forums/topic/posting-user-meta-in-registration-form-on-membership-plugin

    ...which looks good, but I can't find the files the poster is mentioning. Do you know where registration.form.php is located?

    Thanks.

  • Ash

    Hi @martin

    Yes, that solution looks promising. But the file is changed in latest version.

    For now, you need to go first /plugins/membership/membershipincludes/includes/account.form.php near line no 42

    And the you will find

    $user_id = wp_create_user( sanitize_user( $_POST['user_login'] ), $_POST['password'], $_POST['user_email'] );

    in /plugins/membership/membershipincludes/classes/membershippublic.php line no 1223 and 1366.

    Please let me know if that works for you.

    Cheers
    Ash

  • martin

    Hi Ash,

    Thanks for the help. I may be a step nearer. I've found the two files and added the code from the other post but it doesn't seem to have added the field to either the WordPress Users section or to the sign-up form. I've scanned through the rest of the code in membershippublic.php but with no luck.

    Just so I'm clear, should these edits add to the WordPress Users page or the Membership sign-up form that is output on our Join Now page here.

  • Ash

    Hi @martin

    Please go to /plugins/membership/classes/Membership/Render/Page/Registration/Standard.php line no 154:

    <div class="form-element">
    						<label class="control-label" for="address"><?php _e('Address', 'membership'); ?></label>
    						<div class="element">
    							<input type="text" class="input-xlarge" name="address" id="address" required placeholder="" value="<?php echo esc_attr($_POST['address']) ?>" />
    						</div>
    					</div>

    Then go to /plugins/membership/membershipincludes/classes/membershippublic.php line no 1224, you will see:
    $user_id = wp_create_user( sanitize_user( $_POST['user_login'] ), $_POST['password'], $_POST['user_email'] );
    And below that put the following:
    update_usermeta($user_id, 'address', esc_attr($_POST['address']));

    You can get the value by the following code:

    echo get_usermeta($current_user->ID, 'address');

    Please note that, this changes will be lost in next update. So it's worth to note down this changes somewhere and apply again after your updates.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.