• Resolved Selah

    (@tubescreamer)


    Hi, I have figured out how to display a custom field on my register form on the user’s account page (/account/general) and make the field uneditable/not saveable from the front-end. On the register form for this particular field (whose meta key is cust_acct_num), I have set some Help Text to show up in the UM tooltip. I am trying to get this same Help Text data to show up for the custom field in the account page. The code I have below adds the little info icon next to the label and displays the tooltip when hovering over it, but it’s not dynamic, so if I add another custom field to be displayed in the account page, it will show the same tooltip text for that other field as well.

    add_action('um_before_account_general', 'account_additional_disabled_fields', 100);
     
    function account_additional_disabled_fields(){
        $custom_fields = [
            "cust_acct_num" => 'Account Number',
        ];
        foreach ($custom_fields as $k => $title) {
            $fields[ $k ] = array(
                'title' => $title,
                'metakey' => $k,
                'type' => 'select',
                'label' => $title,
            );
            apply_filters('um_account_secure_fields', $fields, get_current_user_id());
     
            $val = get_field($k, 'user_'.get_current_user_id() ) ? get_field($k, 'user_'.get_current_user_id() ) : '';
     
            $html = '<div class="um-field um-field-text  um-field-'.$k.' um-field-text um-field-type_text" data-key="'.$k.'">
                    <div class="um-field-label">
                        <label for="user_'.$k.'">'.$title.'</label>
                        <span class="um-tip um-tip-w" original-title="Your account number"><i class="um-icon-help-circled"></i></span>
                        <div class="um-clear"></div>
                    </div>
                    <div class="um-field-area">
                        <input disabled="disabled" class="um-form-field valid " type="text" name="'.$k.'" id="user_'.$k.'" value="'.$val.'" placeholder="" data-validate="" data-key="'.$k.'">
                    </div>
                </div>';
            echo $html;
        }
             
    }

    This is the line above that I have added to display the info icon and tooltip <span class="um-tip um-tip-w" original-title="Your account number"><i class="um-icon-help-circled"></i></span>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @tubescreamer

    I suggest that you try the approach in this tutorial so that it renders all field elements.

    Regards,

    Thread Starter Selah

    (@tubescreamer)

    Thanks.. i’ll take a look. But is there no way to do the above?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @tubescreamer

    You can try this code snippet:

    add_action('um_before_account_general', 'account_additional_disabled_fields', 100);
    function account_additional_disabled_fields(){
        $custom_fields = [
            "cust_acct_num" => [
                'title' => 'Account Number',
                'help' => 'Your account number'
            ],
        ];
        foreach ($custom_fields as $k => $data ) {
            $fields[ $k ] = array(
                'title' => $data['title'],
                'metakey' => $k,
                'type' => 'select',
                'label' => $data['title'],
            );
            apply_filters('um_account_secure_fields', $fields, get_current_user_id());
     
            $val = get_field($k, 'user_'.get_current_user_id() ) ? get_field($k, 'user_'.get_current_user_id() ) : '';
     
            $html = '<div class="um-field um-field-text  um-field-'.$k.' um-field-text um-field-type_text" data-key="'.$k.'">
                    <div class="um-field-label">
                        <label for="user_'.$k.'">'.$data['title'].'</label>
                        <span class="um-tip um-tip-w" original-title="'.$data['help'].'"><i class="um-icon-help-circled"></i></span>
                        <div class="um-clear"></div>
                    </div>
                    <div class="um-field-area">
                        <input disabled="disabled" class="um-form-field valid " type="text" name="'.$k.'" id="user_'.$k.'" value="'.$val.'" placeholder="" data-validate="" data-key="'.$k.'">
                    </div>
                </div>';
            echo $html;
        }
             
    }

    You need to include the help text in the array. Here’s an example:

    $custom_fields = [
            "cust_acct_num" => [
                'title' => 'Account Number',
                'help' => 'Your account number'
            ],
    ];

    And if you need a new field, just do the following:

    $custom_fields = [
            "cust_acct_num" => [
                'title' => 'Account Number',
                'help' => 'Your account number'
            ],
            "hello_world" => [
                'title' => 'Hello World',
                'help' => 'This is a wild world'
            ],
    ];

    Regards,

    Thread Starter Selah

    (@tubescreamer)

    Ah I see, thanks! I thought it would be able to automatically pull the already existing help text from the custom field that I created in Ultimate Member > Forms > Register Form. I wasn’t aware I had to manually type it in the array as well.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @tubescreamer

    There’s no reference to call the custom fields data in your code so you have to manually add it.

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Fetch and display tooltip value for specific field with PHP’ is closed to new replies.