Hello everybody,
we have the following Problem:
One normal text fields, which is optional if a hidden field has value 1. By default its required.
Without this dependency rule, everything works fine. If there is a dependency rule the value is not updated in (form.inc 1968f) $form_state.
$process_input = empty($element['#disabled']) && ($form_state['programmed'] || ($form_state['process_input'] && (!isset($element['#access']) || $element['#access'])));
is giving back false, so it loads the empty value from the cache.
Ive added some other text fields with other technical names and could reproduce this error.
[UPDATE]
i now know why the value is not updated. The following if-statement is been executed:
if (empty($field['reset'])) {
unset($field_values_location[$dependent['#field_name']]);
}
I removed this line (see code below) and now it works all fine..
function conditional_fields_form_validate($form, &$form_state) {
if (empty($form_state['conditional_fields_untriggered_dependents'])) {
return;
}
$untriggered_dependents_errors = array();
foreach ($form_state['conditional_fields_untriggered_dependents'] as $field) {
$dependent = drupal_array_get_nested_value($form, $field['parents']);
$field_values_location = conditional_fields_form_field_get_values($dependent, $form_state);
// If we couldn't find a location for the field's submitted values, let the
// validation errors pass through to avoid security holes.
if (!isset($field_values_location[$dependent['#field_name']])) {
continue;
}
if (empty($field['reset'])) {
// Steffen s002 hack
//unset($field_values_location[$dependent['#field_name']]);
}
else {
$dependent_info = field_form_get_state($dependent['#field_parents'], $dependent['#field_name'], $dependent['#language'], $form_state);
$field_values_location[$dependent['#field_name']][$dependent['#language']] = field_get_default_value($dependent_info['instance']['entity_type'], NULL, $dependent_info['field'], $dependent_info['instance'], $dependent['#language']);
}
// Save the changed array back in place.
// Do not use form_set_value() since it assumes that the values are located at
// $form_state['values'][ ... $element['#parents'] ... ], while the
// documentation of hook_field_widget_form() states that field values are
// $form_state['values'][ ... $element['#field_parents'] ... ].
drupal_array_set_nested_value($form_state['values'], $dependent['#field_parents'], $field_values_location);
if (!empty($field['errors'])) {
$untriggered_dependents_errors = array_merge($untriggered_dependents_errors, $field['errors']);
}
}
if (!empty($untriggered_dependents_errors)) {
// Since Drupal provides no clean way to selectively remove error messages,
// we have to store all current form errors and error messages, clear them,
// filter out from our stored values the errors originating from untriggered
// dependent fields, and then reinstate remaining errors and messages.
$errors = array_diff_assoc((array) form_get_errors(), $untriggered_dependents_errors);
form_clear_error();
$error_messages = drupal_get_messages('error');
$removed_messages = array_values($untriggered_dependents_errors);
// Reinstate remaining errors.
foreach ($errors as $name => $error) {
form_set_error($name, $error);
// form_set_error() calls drupal_set_message(), so we have to filter out
// these from the messages to avoid duplicates.
$removed_messages[] = $error;
}
// Reinstate remaining error messages (which, at this point, are messages that
// were originated outside of the validation process).
foreach (array_diff($error_messages['error'], $removed_messages) as $message) {
drupal_set_message($message, 'error');
}
}
}
Does anybody have any clue why $field['reset'] is empty?
Callstack is:
sites/all/modules/conditional_fields/conditional_fields.module.conditional_fields_form_validate:774
includes/form.inc.form_execute_handlers:1453
includes/form.inc._form_validate:1395
includes/form.inc.drupal_validate_form:1129
includes/form.inc.drupal_process_form:843
includes/form.inc.drupal_build_form:373
includes/form.inc.drupal_get_form:130
modules/node/node.pages.inc.node_add:73
includes/menu.inc.call_user_func_array:0
includes/menu.inc.menu_execute_active_handler:517
index.php.{main}:21
[UPDATE2]:
Ive found someone who has the some problem: http://drupal.org/node/1542706#comment-6335834
Does anyone know if theres another bugfix than http://drupal.org/node/1542706#comment-6333454 ?
Thanks in advance.
Comments
Comment #0.0
iTiZZiMO CreditAttribution: iTiZZiMO commentedUpdated Callstack
Comment #1
andypostDuplicate of #1542706: Conditional fields not saving
Comment #1.0
andypostfound dirty bugfix, but this cant be it...