0

I need a custom user_profile_form in a page of my drupal site containing a subset of fields provided by the form. I created it and rendered it this way:

function mymodule_join_experiment_contr_strict_mode($exp_node, &$form, &$form_state) {
  module_load_include('inc', 'user', 'user.pages');
  global $user;  
  $user = user_load($user->uid);
  $form = drupal_get_form('user_profile_form', $user, 'account', 'strict_mode'); 
  return $form;
}

Now in my custom function mymodule_form_user_profile_form_alter(&$form, &$form_state, $form_id) i'm doing

$form['picture']['#access']=FALSE;

in order to hide the field 'picture' and any other field i need to hide. In the form i have two collapsible named 'location' and 'timezone', provided, i think, by 'location' or 'gmap' module. (I didn't realized all this site so i don't really know everything about it.) Now, even looking at $form i can't see the equivalent for timezone and location. I expected to find something that allowed me to do

$form['timezone']['#access']=FALSE;

but i cannot find timezone and location... What i am doing wrong?

EDIT: i'm trying to get what is the right way to do it in drupal, before to surrender and use a 'display:none' on css

2 Answers 2

3

Solved. I had to use the solution suggested #35

This is the code i used

<?php
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'MYNODETYPE_node_form') {
    $form['#after_build'][] = 'MYMODULE_SOMETHING_MEANINGFUL';
  }
}

function MYMODULE_SOMETHING_MEANINGFUL($form_element, &$form_state) {
  //note that I only have one location on this node type
  $form_element['locations']['#access']=FALSE;
  $form_element['timezone']['#access']=FALSE;

  return $form_element;
}
?>

I have not quite understood what is going on. An explanation about after_build would be appreciated.

3
  • very low quality link only answers are not entertained. This answer has severe formatting or content problems. This answer is unlikely to be salvageable through editing, and might need to be removed.
    – niksmac
    Commented Jul 7, 2015 at 11:59
  • 1
    I corrected the answer to show code. It seemed to me useful to know all the discussion for someone finding this solution. Commented Jul 7, 2015 at 12:09
  • 1
    Your effort is much appreciated +1
    – niksmac
    Commented Jul 8, 2015 at 3:53
0

Timezone settings can be disabled on this page admin/config/regional/settings. And user pictures can be disabled on this page admin/config/people/accounts

1
  • Yes, but i do not want to disable it. I just want to disable it a specific custom page i'm building. It appears for the base of the page is the default user_profile_form, and i do not know how to hide it. Commented Jul 7, 2015 at 11:29

Your Answer

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

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