Drupal 6: How to set a form field created with CCK as disabled

Drupal 6: Como establecer un campo de formulario creado con CCK como desactivado

Form fields are very easy to manipulate using a  form_alter  in a module, however when we are dealing with fields created with  CCK (Content Construction Kit)  the story is a little different because these fields are created at the end of the form construction, in such a way that any changes we need to make must be done between the construction of the form and the rendering.

 

#after_build

 

In the  hook_form_alter  we need to define the function that will be executed after the form is built using the special element  #after_build  ( http://api.drupal.org/api/drupal/developer--topics--forms_api_reference… )

 

function mymodule_form_alter(&$form, &$form_state, $form_id){

  ...

  $form['#after_build'][] = 'mymodule_after_build';

  ...

}

 

The next step is to create the function we specified and make the change to the change by specifying the 'disabled' attribute

 

function mymodule_after_build($form, &$form_state){

  ...

  $form['field_myfield'][0]['value']['#attributes']['disabled'] = TRUE;

  ...

 

  return $form;

}

 

If you have any concerns or contributions to make, please contact us through this  form  or our Twitter account  @seedcolombia