I'm putting a node add form on a custom page that is a menu local task tab for specific taxonomy terms, and trying to set default values for some of the elements.
I'm building the form like this:
function emtr_form($form, &$form_state) {
module_load_include('inc', 'node', 'node.pages');
$form = node_add('mtr');
$form['field_shift'][LANGUAGE_NONE]['#default_value'] = 'early';
// also tried this but it doesn't work either
//$form[LANGUAGE_NONE]['early']['#default_value'] = true;
}
When I inspect the form array I can see:
#options (Array, 3 elements)
early (String, 13 characters ) 23:00 - 07:00
lunch (String, 13 characters ) 07:00 - 15:00
late (String, 13 characters ) 15:00 - 23:00
#default_value (String, 5 characters ) early
#after_build_done (Boolean) TRUE
This shows my default value matches the options array key, however also shows that #after_build is done. I suspect that the default value gets set in the after build function, however if I set after build to false I seem to get caught in an endless loop and the browser crashes.
I tried adding my own custom after_build function to the form and setting the default values there, but because after_build has already been done it is never called.
How can I set default values when building a form like this? Or is there a better way to load the node add form?
EDIT: Here is a paste bin with the whole form item array
EDIT2: This is a radios field that is part of a field collection that is part of a node add form.