There were several notices so I added some empty checks.

CommentFileSizeAuthor
form_builder_notices.patch2.47 KBindytechcook

Comments

quicksketch’s picture

Could you describe when each of these notices occurs?

indytechcook’s picture

Sure, I'm using form_builder an API module and not via webforms. The notices occurred anytime I displayed the form builder UI.

I created http://drupal.org/project/form_builder_field to display the form. It is possible that "I'm Doing it Wrong(tm)"

Oh yeah, great module!

quicksketch’s picture

Status: Needs review » Postponed (maintainer needs more info)

I can't see why this patch should be necessary. I'm guessing that Form Builder is encountering an improperly formatted $form variable. In each of the places where you've added a check, it's just after a call to element_children(), which should ensure that the particular key you're checking should exist.

Take form_builder_get_element_types() for example:

function form_builder_get_element_types($form) {
  $element_types = array();
  foreach (element_children($form) as $key) {
    if (isset($form[$key]['#form_builder']['element_type'])) {
      $element_types[] = $form[$key]['#form_builder']['element_type'];
    }
    $additional_types = form_builder_get_element_types($form[$key]);
    $element_types = array_merge($element_types, $additional_types);
  }

  return $element_types;
}

And your patch segment:

@@ -287,8 +287,10 @@ function form_builder_get_element_types($form) {
     if (isset($form[$key]['#form_builder']['element_type'])) {
       $element_types[] = $form[$key]['#form_builder']['element_type'];
     }
-    $additional_types = form_builder_get_element_types($form[$key]);
-    $element_types = array_merge($element_types, $additional_types);
+    if (!empty($form[$key])) {
+      $additional_types = form_builder_get_element_types($form[$key]);
+      $element_types = array_merge($element_types, $additional_types);
+    }
   }

$form[$key] shouldn't ever be empty to begin with, since you just got back it as an existing key from element_children().

This problem looks like it may be caused by having a FAPI array that looks like this, where not all the children are proper elements:

$form['element1'] = array(
  '#type' => 'textfield',
);
$form['element2'] = 'textfield';

Or perhaps a simple mistake like this:

$form['element1'] = array(
  '#type' => 'textfield',
  'value' => '',
);

Because 'value' doesn't have a hash sign, Drupal will think that 'value' is a sub-field of element1.

I would try printing out your entire FAPI array and also print out the $key value in the places you've patched Form Builder to figure out which $key is giving you an empty value. Then see if that $key relates to a malformed part of your FAPI array.

quicksketch’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Please reopen if you can provide more information on when this problem occurs, or if it seems that my guesses in #3 were off mark.