With the latest version of Form Builder, Webform and Drupal core (plus a bazillion other modules) I get this error when the Webform fields page loads:
Warning: Invalid argument supplied for foreach() in element_children() (line 6248 of includes/common.inc).
I'm going to debug it soon, but wanted to have somewhere to track the progress.

Comments

quicksketch’s picture

Hm, yeah I don't get this error with a basic install of D7, Webform, and Form Builder. Any module that extends Webform in some way beyond the core components probably will not work with Form Builder.

tom verhaeghe’s picture

I too have this error. It only occurs when the form has not been saved yet. Once I save the form, even if empty, the warning disappears.

Warning: Invalid argument supplied for foreach() in element_children() (line 6244 of includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6244 of includes/common.inc).
quicksketch’s picture

Hi Tom, is it possible to reproduce this problem from a clean install of Drupal and Form Builder?

ryan.armstrong’s picture

I have this same issue with a clean install, no modules except for webform, options, form builder, and the webform builder UI. I've noticed that it only happens when I try to add invisible element components and then I hit save. Upon hitting save, the invisible component disappears. If I use devel and take a look at the webform node, I can see the hidden component in the node->webform['components']. It looks ot be correct. It's just in the Form Builder UI that it doesn't show up and causes the error. Also the error is on a slightly different line:

Warning: Invalid argument supplied for foreach() in element_children() (line 6124 of /Applications/MAMP/htdocs/multisite/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6124 of /Applications/MAMP/htdocs/multisite/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6124 of /Applications/MAMP/htdocs/multisite/includes/common.inc).

tom verhaeghe’s picture

I'll try. Give me a day :-)

tom verhaeghe’s picture

StatusFileSize
new1.25 KB

I reproduced the error in the following module (see attachment).

I guess the error happens when $form_structure is an empty array (line 29 in formbuilder_error.module). In my module it happens when no form has been saved in my cache table.

quicksketch’s picture

I've noticed that it only happens when I try to add invisible element components and then I hit save. Upon hitting save, the invisible component disappears.

Could you describe what you mean by "invisible component"? What are these and how do you add one to the form?

quicksketch’s picture

Status: Active » Postponed (maintainer needs more info)

If you mean the "Private" option is checked, you may need to make sure that your user account has "Access all webform results" permission. I hadn't thought about this requirement until I put together these two patches, which may also fix the problem. Even though these have to do with page breaks, the code touches on private and conditional components also:

#1507718: Return entire form if $filter = FALSE in webform_client_form() to simplify Form Builder integration
#1507728: Clean up pagebreak code, fixing notices and nested pagebreaks

ryan.armstrong’s picture

Sorry, I am referring to a hidden component. I add them by just dragging over the hidden component from the list of components (like textarea, date, select, etc) onto the form area.

quicksketch’s picture

Thanks for the clarification @ryan.armstrong, I'll try to reproduce it again and see if I can get the error.

damienmckenna’s picture

I should have explained that on my tests I had about a dozen hidden fields.

ryan.armstrong’s picture

On mine I had 4-5 and they were all at the top. Don't think that matters, but I thought I would add it just in case :)

indolering’s picture

Any updates on this issue?

quicksketch’s picture

Title: Invalid argument supplied for foreach() in element_children() » Invalid argument supplied for foreach() in element_children() when Hidden components are used
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new0 bytes
new30.58 KB

These patches should solve the problem.

quicksketch’s picture

StatusFileSize
new1.51 KB

D7 patch was bunk, here's the proper one.

quicksketch’s picture

StatusFileSize
new1.2 KB

Haha, D6 patch was also bunk. Geez sorry guys.

quicksketch’s picture

Status: Needs review » Fixed

Fix committed to both branches. Unless there is an issue directly with this patch, please keep this issue closed. There are other similar foreach() errors in the queue currently, such as #1510216: Invalid argument webform.components.inc.

damienmckenna’s picture

@quicksketch: Thanks for tracking this one down!

Status: Fixed » Closed (fixed)

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

Pedro Lozano’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new462 bytes

I'm still getting this problem with the latest -dev version.

I'm not totally sure how to reproduce but I'm attaching the patch that fixes it.

Pedro Lozano’s picture

This issue seems related. #1553108: Invalid argument supplied for foreach() in form_builder_webform_form_builder_load() with unknown types

Not exactly the same error but the same solution.

quicksketch’s picture

Status: Needs review » Closed (fixed)

Since this issue has already had patches applied to it, let's use the issue Pedro pointed out to solve this new problem.