1

I know how to use hook_form_alter, but I'm little confused how to achieve this:

In user profile there are tabs "View" and "Edit".

In edit I can alter the form using switch statement on user_profile_form and adding a fields, but they don't appear when I click on "View" tab.

Let's say I'm adding a new field into the user_profile_form:

    <?php

    /*
     * Implements hook_form_alter().
     */

    function my_module_form_alter (&$form, &$form_state, $form_id) {
            switch ($form_id) {
            case 'user_profile_form':


    $form['account']['skype_title'] = array(
            '#type' => 'markup',
            '#markup' => '<div class="user-profile-skype">Skype edit</div>'
            );

            $form['account']['skype'] = array(
            '#type' => 'textfield',
            '#title' => t('New Skype'),
            );

                  //krumo($form);   
            break;  

    }
}

How can I display this field into "View tab"?

Should I use another hook for this?

4
  • Why not just use the standard Field API and add fields to the user account entity? Sep 30, 2013 at 8:48
  • You mean by creating a custom module with field API or adding fields from here: admin/config/people/accounts/fields? Sep 30, 2013 at 9:28
  • Adding fields from admin/config/people/accounts/fields Sep 30, 2013 at 9:29
  • First, I've tried that and added the text fields that I need. Later I wanted to display only a title without textfield, I mean only show as a title, but on Fields UI I didn't find that option. Sep 30, 2013 at 11:21

2 Answers 2

1

As Kaido24 mentioned, the profile view tab is not a form. You can add elements to it in hook_user_view_alter().

1
  • This is an old thread and yes, your answer is right even tough I'm not using Drupal anymore. Sep 19, 2016 at 12:30
0

View tab is rendered view not a form. If you would like to show something at view tab then iguess you could use the hook_page_alter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.