Support Forum
Support › MB User Profile › How to modify deafult fields specifically on front-end User Registration FormResolved
Is this even possible? I'm trying to modify the fields that are included with the default fields group that loads when you use the registration form shortcode. I'd like to do this in MB builder if possible, but code is OK too. Basically I'm trying to add the default WP First and Last name fields in with that first group that already has username, password, email, etc. so that it's all together.
Hi John,
There is no option to add a custom field to the registration form in the builder. With coding, you can follow these topics to know how to modify the registration form by using the filter hook rwmb_profile_register_fields
https://support.metabox.io/topic/mb_user_profile_register-autocompletenew-password/
https://support.metabox.io/topic/duplicated-register-forms
This is extremely helpful, thank you!
Okay, follow up question:
I have followed the examples you shared, and ended up with the resulting code:
//adapted from: https://support.metabox.io/topic/mb_user_profile_register-autocompletenew-password/
//relevant docs: https://docs.metabox.io/extensions/mb-user-profile/#form-fields-filters
function add_more_registration_fields( $fields ) {
$fields = [
'first_name' =>[
'id' => 'first_name', // THIS
'name' => 'First Name',
'type' => 'text',
'required' => true,
'columns' => 4,
],
'last_name' =>[
'id' => 'last_name', // THIS
'name' => 'Last Name',
'type' => 'text',
'required' => true,
'columns' => 4,
],
'username' => [
'name' => __( 'Username', 'mb-user-profile' ),
'id' => 'user_login',
'type' => 'text',
'required' => true,
'columns' => 4,
],
'email' => [
'name' => __( 'Email', 'mb-user-profile' ),
'id' => 'user_email',
'type' => 'email',
'required' => true,
'columns' => 6,
'desc' => 'Used for notifications and alerts (if opted-in).',
],
'phonenumber' => [
'name' => __( 'Phone Number', 'mb-user-profile' ),
'id' => 'phonenumber',
'type' => 'tel',
'required' => true,
'desc' => 'Used for notifications and alerts (if opted-in).',
'columns' => 6,
],
'password' => [
'name' => __( 'Password', 'mb-user-profile' ),
'id' => 'user_pass',
'type' => 'password',
'required' => true,
'columns' => 6,
'desc' => '<span id="password-strength" class="rwmb-password-strength"></span>',
'attributes' => [
'autocomplete' => 'new-password'
]
],
'password2' => [
'name' => __( 'Confirm Password', 'mb-user-profile' ),
'id' => 'user_pass2',
'type' => 'password',
'required' => true,
'columns' => 6,
],
// ... add more fields here
];
return $fields;
}
add_filter( 'rwmb_profile_register_fields', 'add_more_registration_fields' );
Everything works except the first 2 fields. The first and last name do not get copied into the user meta. I am following the instructions listed here: https://docs.metabox.io/extensions/mb-user-profile/#edit-default-fields. The IDs match. Is there something else I'm doing wrong?
Hi John,
It looks like the registration form does not process other custom fields in the default meta box rwmb-user-register
. You will need to add another meta box (field group) and follow the documentation "edit default fields" to add the first name and last name of the new user.
The filter will help you to modify the field settings of default fields. I will inform the development team to consider supporting this case in future updates.
Thank you.
Thank you, that will work for now. It would be helpful to have this functionality in the future, as it would allow the actual set of default fields to be ordered alongside the others in the registration form.