How to modify deafult fields specifically on front-end User Registration Form

Support MB User Profile How to modify deafult fields specifically on front-end User Registration FormResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #36692
    John RoodJohn Rood
    Participant

    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.

    #36698
    Long NguyenLong Nguyen
    Moderator

    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

    #36702
    John RoodJohn Rood
    Participant

    This is extremely helpful, thank you!

    #36704
    John RoodJohn Rood
    Participant

    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?

    #36707
    Long NguyenLong Nguyen
    Moderator

    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.

    #36723
    John RoodJohn Rood
    Participant

    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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.