Skip to main content
Found out what really works
Source Link
iStryker
  • 4.5k
  • 2
  • 24
  • 44

Edit:

Ok I figured it out. Put this in your custom module:

function example_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'story_node_form') {
        $form['title']['#value'] = 'hot stuff';
        $form['title']['#access'] = FALSE;
        
    }
}

This will set the title of the story node to 'hot stuff' and it will NOT be render on the page because #access = FALSE;

You can add more granularity control inside hook_form_alter() like

  global $user;

  // Check to see if $user has does not have the administrator role.
  if (!in_array('administrator', array_values($user->roles))) {
    $form['title']['#access'] = FALSE;
  }

This works for Drupal 6 & 7.

Old Answer (ignore):

Its been awhile since I did something like this, so I may have it wrong. If you set the [#value] of a form item, it will not be visible on the form.

I did this in Drupal 6, hook_form_alter() in a custom module. I don't know if it will work in Drupal 7 and I don't know if you can do it in a preprocess function

Its been awhile since I did something like this, so I may have it wrong. If you set the [#value] of a form item, it will not be visible on the form.

I did this in Drupal 6, hook_form_alter() in a custom module. I don't know if it will work in Drupal 7 and I don't know if you can do it in a preprocess function

Edit:

Ok I figured it out. Put this in your custom module:

function example_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'story_node_form') {
        $form['title']['#value'] = 'hot stuff';
        $form['title']['#access'] = FALSE;
        
    }
}

This will set the title of the story node to 'hot stuff' and it will NOT be render on the page because #access = FALSE;

You can add more granularity control inside hook_form_alter() like

  global $user;

  // Check to see if $user has does not have the administrator role.
  if (!in_array('administrator', array_values($user->roles))) {
    $form['title']['#access'] = FALSE;
  }

This works for Drupal 6 & 7.

Old Answer (ignore):

Its been awhile since I did something like this, so I may have it wrong. If you set the [#value] of a form item, it will not be visible on the form.

I did this in Drupal 6, hook_form_alter() in a custom module. I don't know if it will work in Drupal 7 and I don't know if you can do it in a preprocess function

Source Link
iStryker
  • 4.5k
  • 2
  • 24
  • 44

Its been awhile since I did something like this, so I may have it wrong. If you set the [#value] of a form item, it will not be visible on the form.

I did this in Drupal 6, hook_form_alter() in a custom module. I don't know if it will work in Drupal 7 and I don't know if you can do it in a preprocess function