I'm using the module to customize forms generated from a "Base Form" defined with Webform Default Fields.
Sometimes, after save multiple changes (move, modify, add or delete fields) on a form, it crashes with errors like

Notice: Undefined index: element_id a FormBuilderFormBase->_recursiveElementIds() (line 670 of .../sites/all/modules/form_builder/form_builder.classes.inc).

or

Fatal error: Call to a member function render() on a non-object in .../sites/all/modules/form_builder/form_builder.classes.inc on line 737

Analyzing it I found that, for some reason, an element with an empty key is generated causing errors on the code. My patch don't fix the generation of this empty elements but avoid the errors

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fcasanellas created an issue. See original summary.

mls09121’s picture

I'm not to familiar with adding patches, but I'm having the same issue. Its actually quite a terrible bug because it blocks you from even using the regular webform-- you have to disable the module. I get:

Notice: Undefined index: element_id in FormBuilderFormBase->_recursiveElementIds() (line 670 of /var/www/html/public_html/sites/all/modules/form_builder/form_builder.classes.inc).
Notice: Undefined index: element_id in FormBuilderFormBase->_recursiveElementIds() (line 670 of /var/www/html/public_html/sites/all/modules/form_builder/form_builder.classes.inc).

I'm confused as to where to paste the code from the patch though. Could you please explain? There are a number of different files in the module folder.
Thank you!

fcasanellas’s picture

It's easy, just edit the file form_builder.classes.inc replacing the line 669 that contains
if (isset($e[$key]['#form_builder'])) {
for:
if ($key && isset($e[$key]['#form_builder'])) {

genjohnson’s picture

Status: Active » Needs review

Changing status to "needs review" since a patch has been provided.

torotil’s picture

Status: Needs review » Needs work

Hi first thanks for your work on this!

If the problem is that an empty element is created at some point then that's the problem to solve. A patch that covers symptoms is always a bad idea. So any idea how/why this empty element is created?

inhelli’s picture

Cause is moving components with same keys in one scope (page or fieldset)

I tried to solve it this way:

torotil’s picture

Thanks @inhelli for your patch. I still don't quite understand what triggers this bug. Could you describe a simple test-case for me?

torotil’s picture

Status: Needs work » Needs review
FileSize
1.02 KB

Ok I've found a test case on my own now:

You need at least 3 fields for this to work. Then in one form session do:

  1. Delete one element.
  2. Drag and drop at least one of the remaining.
  3. Save the form.

This fails because the position form in the browser is not updated after an element is deleted - and later when the positions form is submitted it sets the weight/parent of the now non-existent element (creating a broken element) and thus causing the failure.

Here is patch that fixes this.

JayKandari’s picture

This works as expected in latest release of form_builder 7.x-1.20.

grahamC’s picture

Status: Needs review » Fixed

I can see the patch from #8 was committed (http://cgit.drupalcode.org/form_builder/commit/?id=e27755a) and made it into 7.x-1.20, so let's call this fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.