0

I've added some fields to user profile.
None of these fields are displayed on registration form, but I want user can edit them quickly when he is logged.
I want to embed some fields in a static content and display them to the user: how can I manage this? Can I create a php page or is it better using hook_form?

2

This should give you a start. Probably it is not the most elegant solution, but after 5 minutes of hacking, this is what I got. It works, and updates the profile fields (alone).

  function custom_block_info() {
     $blocks['user_profile'] = array(
       'info' => t('User profile edit'),
       'cache' => DRUPAL_NO_CACHE,
     );

     return $blocks;
    }

    function custom_block_view($delta = '') {
      $block = array();

      switch($delta) {
        case 'user_profile':
          $block['subject'] = t('Fill your profile');
          $block['content'] = drupal_get_form('custom_profile_form');
          break;
      }

      return $block;
    }

    function custom_profile_form($form, &$form_state) {
      global $user;

      $form_state['user'] = $user;
      $form['#user'] = $user;
      $form['#user_category'] = 'account';
      $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#weight' => 100,
        '#value' => t('Save'),
      );

      $form['#action'] = url('user/' . $user->uid . '/edit');
      // $form['#validate'][] = 'user_profile_form_validate';
      $form['#submit'][] = 'user_profile_form_submit';
      field_attach_form('user',$user,$form,$form_state);

      return $form;
    }
  • what category are you talking about? drupal_get_form doesn't take any parameters but form_id. Please notice that I don't want to display the whole form (username, password, mail) I just want the two fields I need. – pasine May 2 '11 at 16:24
  • api.drupal.org/api/drupal/modules--user--user.pages.inc/… The last parameter category decides which form appears, so basically if u define any profile field u need to define it in a category, visit admin/user/profile and try to add any new profile field and it will ask u for a category, also ur existing profile field must be belonging to some category. – Dipen May 2 '11 at 20:20
  • Sorry, but this issue is related to D7, that doesn't have a profile module anymore. I've seen the category parameter, but I don't know how to add it to a field. – pasine May 2 '11 at 20:32
  • hey, I have updated the answer to reflect drupal 7. I somehow assumed it to be a drupal 6 question. See if it works for you, it needs to go in a custom module called 'custom'. – Dipen May 2 '11 at 22:18
  • 1
    You should ask this as a new question and reference to this, nobody is going to look at this. You should also provide more details when creating a question. – Berdir May 19 '11 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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