1

I'm using Entityform with some custom module for multipage which is based on FGAM.

Recoverable fatal error: Argument 2 passed to drupal_array_get_nested_value() must be of the type array, string given, called in includes/form.inc on line 1200 and defined in drupal_array_get_nested_value() (line 6771 of includes/common.inc).

The website encountered an unexpected error. Please try again later.

Why this happens and how do I fix or debug this kind of error?

1 Answer 1

3

The error:

Argument 2 passed to drupal_array_get_nested_value() must be an array, string or null given

means there is a problem with the structure of your form you're trying to submit. So string/NULL were given instead of array for the second parameter.

The function:

&drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL)

retrieves a value from a nested array with variable depth, for example:

$value = drupal_array_get_nested_value($form, $parents);

Here are the example calls from Drupal core (see the 2nd argument):

./common.inc:  drupal_array_get_nested_value($array, $parents, $key_exists);
./form.inc:      $input = drupal_array_get_nested_value($form_state['input'], $element['#parents'], $input_exists);
./form.inc:  $source = drupal_array_get_nested_value($form_state['complete form'], $element['#machine_name']['source'], $key_exists);

If you don't know which field is causing it, the easiest way to find out is by doing this simple hack (which should be reverted after that of course):

function &drupal_array_get_nested_value(array &$array, $parents, &$key_exists = NULL) {
  if (!is_array($parents)) { var_dump($parents, debug_backtrace()); exit; }

Which would display value of $parents which should be an array and the backtrace.

Usually this could happen during the validation and it can caused by invalid #parents or #limit_validation_errors structure of form array.

If there is no any custom coding involved, then it's a bug of the contrib module which cause that (e.g. Conditional Fields, Email Field, Entity Translation, etc.), so it should be reported against the right module.


In my specific case, I've to fix #limit_validation_errors by wrapping it into array() where it contained list of $group['children']:

  $form['actions']['continue'] = array(
    '#type' => 'submit',
    '#value' => t('Continue'),
    '#limit_validation_errors' => array($validate_fields),
    '#submit' => array('foo_form_submit'),
    '#validate' => array('foo_form_validate'),
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.