Custom Fields
Re-Envisioned
Support MB User Profile The subfields first_name and last_name cannot be saved.

  • Creator
    Topic
  • #29306
    Yumikom
    Participant

    Hi,

    My registration form does not allow me to save my first and last name.
    I am using mb_user_profile_register to display the MB User Profile custom fields as follows.
    Is it possible to make this work correctly with subfields?
    By the way, I was able to save "last_name_kana" and "first_name_kana" correctly.

    
    [mb_user_profile_register id="user-profile" form_id="form-registration" email_as_username="true" password_strength="false" label_submit="送信する" confirmation="登録を完了しました" label_email="メールアドレス" label_password="パスワード" label_password2="パスワード(確認用)"]
    
    
    <?php
    add_filter('rwmb_meta_boxes', 'your_prefix_function_name');
    
    function your_prefix_function_name($meta_boxes) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'  => __('会員情報', 'your-text-domain'),
            'id'     => 'user-profile',
            'type'   => 'user',
            'fields' => [
                [
                    'name'   => __('ご担当者名', 'your-text-domain'),
                    'id'     => $prefix . 'group_name',
                    'type'   => 'group',
                    'class'  => 'row-name row-required',
                    'fields' => [
                        [
                            'name'       => __('姓', 'your-text-domain'),
                            'id'         => $prefix . 'last_name',
                            'type'       => 'text',
                            'required'   => true,
                            'attributes' => [
                                'placeholder' => 'ご担当者名 姓',
                            ],
                        ],
                        [
                            'name'       => __('名', 'your-text-domain'),
                            'id'         => $prefix . 'first_name',
                            'type'       => 'text',
                            'required'   => true,
                            'attributes' => [
                                'placeholder' => 'ご担当者名 名',
                            ],
                        ],
                    ],
                ],
                [
                    'name'   => __('ふりがな', 'your-text-domain'),
                    'id'     => $prefix . 'group_name_kana',
                    'type'   => 'group',
                    'class'  => 'row-name row-required kana',
                    'fields' => [
                        [
                            'name'       => __('姓(かな)', 'your-text-domain'),
                            'id'         => $prefix . 'last_name_kana',
                            'type'       => 'text',
                            'required'   => true,
                            'attributes' => [
                                'placeholder' => 'ふりがな 姓',
                            ],
                        ],
                        [
                            'name'       => __('名(かな)', 'your-text-domain'),
                            'id'         => $prefix . 'first_name_kana',
                            'type'       => 'text',
                            'required'   => true,
                            'attributes' => [
                                'placeholder' => 'ふりがな 名',
                            ],
                        ],
                    ],
                ],            
            ],
        ];
    
        return $meta_boxes;
    }
    
    

    Best regards,
    Yumikom

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #29316
    Long Nguyen
    Moderator

    Hi Yumikom,

    If you want to register/edit the default fields of users on the frontend, please register them as the top fields, not subfields. The default field IDs seem to not work in a group, I will inform the development team to re-check it.

    Please get more details here https://docs.metabox.io/extensions/mb-user-profile/#edit-default-fields

    #29321
    Yumikom
    Participant

    Hi Long,

    Thanks for the quick confirmation.

    I had to use subfields in order to achieve the designed layout.
    By all means, please make it work with subfields!

    In this case, we will use before and after to adjust the layout, or use Javascript to assign the value of the subfield to hidden name="first_name".

    Thank you.

    #29322
    Yumikom
    Participant

    Hi Long,

    One question.
    Is there a function to add a class to the input element?

    Best regards,
    Yumikom

    #29353
    Long Nguyen
    Moderator

    Hi,

    No, the setting class when registering the field will add custom class to the class rwmb-field, screenshot https://share.getcloudapp.com/bLukQpjp

    [
        'name'       => __('Display Name', 'your-text-domain'),
        'id'         => $prefix . 'display_name_',
        'type'       => 'text',
        'required'   => true,
        'attributes' => [
            'placeholder' => 'ご担当者名 名',
        ],
        'class' => "my-custom-field-class"
    ],

    Then you can the custom class as a selector to track the input.

    .my-custom-field-class #field-ID

    #29354
    Yumikom
    Participant

    Hi Long,

    It's still just adding a class to the wrapper.
    I am using a library to auto-fill the zip code.
    I needed a class for input, so it would have been nice to be able to set it up easily.
    This time, I will add the class to input in Javascript.
    Thank you.

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