Why is the field collection portion of my node form not saving? I am working on a form that collects travel plans from staff members. As part of this I have a nested field collection to collect itineraries and legs within those itineraries.
to give you a rough description of the related fields:
This is not all the fields on the form, but this should give the idea of the structure. I fill out the form, save, and the saved node contains all the other information, but nothing that was in the field collections shows up.
Since country is an additional module, I tried deleting the country field, but that didn't solve anything. I'm also using the conditional fields module extensively to show and hide other fields though the fields in the field collection are not affected by this.
Finally I'm using a custom module called missions (UPDATE: I've disabled the module, and the problem persists, so it seems not to have been the form_alter) to show one field in the field_mr_fc_legs field collection when field_mr_home_leave is checked. The entire code of which can be found below:
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function missions_form_mission_request_node_form_alter(&$form, &$form_state, $form_id)
{
$form['body'][LANGUAGE_NONE][0] += array(
'#placeholder' => t('Day 1
* Activity 1
* Activity 2
Day 2'),
);
$form['field_mr_home_leave'][LANGUAGE_NONE]['#ajax'] = array(
'callback' => 'missions_hide_home_leave_toggle',
'wrapper' => 'itinerary-section',
);
$form['field_mr_fc_itineraries']['#prefix'] = '<div id="itinerary-section">';
$form['field_mr_fc_itineraries']['#suffix'] = '</div>';
if ((!empty($form_state['complete form']['field_mr_home_leave']['und']['#value']) && $form_state['complete form']['field_mr_home_leave']['und']['#value'] == 1) || (empty($form_state['values']['field_mr_home_leave']) && $form['field_mr_home_leave'][LANGUAGE_NONE]['#default_value'] == 1)) {
$home_leave_toggle_access = true;
} else {
$home_leave_toggle_access = false;
}
foreach ($form['field_mr_fc_itineraries'][LANGUAGE_NONE] as $key => &$itinerary) {
if (is_integer($key)) {
foreach ($itinerary['field_mr_fc_legs'][LANGUAGE_NONE] as $key => &$leg) {
if (is_integer($key)) {
$leg['field_mr_fc_leg_home_leave']['#access'] = $home_leave_toggle_access;
}
}
}
}
}
function missions_hide_home_leave_toggle($form, $form_state) {
return $form['field_mr_fc_itineraries'];
}
What is the likely cause of this? The Recent log messages report shows just that the node was updated. Is it my module? Is it nested field collections?
What I've tried
- I disabled my module, and it didn't make a difference
- I removed the nested field collection and it didn't make a difference.
- I removed the country field to verify that it wasn't the country module causing the issue.
- The issue seems to be caused by conditional fields, when I disable that, the form saves properly.