How to alter CCK form fields programmatically

This is how you can alter CCK form fields programmatically in your module. As you might noticed you can't find your CCK fields in the regular form_alter hook. First you have to add a afterbuild function in form_alter and then in the after build function make your changes, add validation and other changes.

<?php
function my_module_form_alter(&$form, &$form_state, $form_id) {
   if (
$form_id = "log_node_form ") {
     
$form['#after_build'][] = 'my_module_after_build';
   }
}

function
my_module_after_build($form, &$form_state) {
  
//Changes
  
return $form;
}
?>

http://drupal.org/node/726282 - hook_form_alter() and CCK fields

Knowledge keywords: