I have had no luck trying to set the value of a field in a field group. I can see in the array that the default value has changed but the change does not show up in the viewed form. This is the same whether I place the code in form_alter or after_build.
If the field is not in the field group, the changed value is visible in the viewed form.
This is the code I'm testing:
<?php
/**
* Modify CCK form elements on the example node form.
*/
function test_after_build($form, &$form_state) {
// $form['field_collection']['und'][0]['value']['#default_value'] = t('Smithfield');
dsm($form); // pretty print array using Krumo to messages
return $form;
}
/**
* Implementation of hook_form_alter().
*/
function test_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'test_record_node_form') {
// target a specific form
drupal_set_message("Form ID is : " . $form_id);
$form['field_collection']['und'][0]['value']['#default_value'] = t('Smithfield');
// Add an after_build function to process when everything's complete.
$form['#after_build'][] = 'test_after_build';
dsm($form); // pretty print array using Krumo to messages
}
}
?>
I don't know what I need to add to this to make it work. Help appreciated.