When the example field is added to a field collection the field validation function produce the following errors:

Notice: Undefined index: field_example in field_example_3text_validate() (line 325 of /sites/all/modules/examples/field_example/field_example.module).
Warning: preg_match() expects parameter 2 to be string, array given in field_example_field_validate() (line 85 of /sites/all/modules/examples/field_example/field_example.module).

Comments

mile23’s picture

cameron prince’s picture

I resolved this in my custom field by using this code for my validate function:

function _my_element_validate($element, &$form_state, $form) {

  $field_name = $element['#field_name'];
  $delta = $element['#delta'];

  $form_values = drupal_array_get_nested_value($form_state['values'], $element['#field_parents']);

...

I think the drupal_array_get_nested_value() function is the key.

cameron prince’s picture

Looks like we reached the same conclusion. Thanks for posting.

jungle’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

No activity for over 10 years. I am closing this. Please feel free to reopen if necessary.

Thanks!