Reply to comment

The standard way of altering form elements and setting them disabled does not work with cck fields.

<?php
function my_module_form_alter(&$form, &$form_state$form_id) {
  
$form['my_element']['#disabled'] = true
}
?>

The FAPI process handler of the CCK field won't transfer the #disabled attribute to its children elements.
You'll need this snippet to make it work.
<?php
/**
 * implementing hook_form_alter
 */
function my_module_form_alter(&$form, &$form_state$form_id) {
  if (
$form_id == 'some_node_form') {
    
$form['#after_build'][] = '_my_module_after_build';        
  }
}

/**
* Custom after_build callback handler.
*/
function _my_module_after_build($form, &$form_state) {
  
// Use this one if the field is placed inside a fieldgroup.
  
_my_module_fix_disabled($form['some_group']['field_some_field']);
  
  
//When using a field
  //_my_module_fix_disabled($form['field_some_field'];  
  
  
return $form;
}

/**
* Recursively set the disabled attribute of a CCK field
* and all its dependent FAPI elements.
*/
function _my_module_fix_disabled(&$elements) {
  foreach (
element_children($elements) as $key) {
    if (isset(
$elements[$key]) && $elements[$key]) {

      
// Recurse through all children elements.
      
_my_module_fix_disabled($elements[$key]);
    }
  }

  if (!isset(
$elements['#attributes'])) {
    
$elements['#attributes'] = array();
  }
  
$elements['#attributes']['disabled'] = 'disabled';
}
?>

EDIT:
Some useful related stuff. Explains why a hook form alter wont work http://drupal.org/node/726282 and how the FAPI handles cck fields.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.