One quick note before I explain the issue:

I posted an issue yesterday, and in implementing the api I plan to post any other bugs or weird things I find. If you're not quite ready for these types of questions just let me know. I don't want to clog up the queue needlessly. Also, I'm not that patch savy, but theres no time like the present to get my hands dirty. If we reach any resolutions and you'd like patches, let me know and I'll see what I can whip up.

Ok now for the current issue.

I was watching the ajax requests while editing my form and noticed some 500s mixed in. I tracked them down to the remove functionality. After calling

form_builder_cache_field_delete($form_type, $form_id, $element_id);

the api tries to print some json output for the field. If my understanding of cache_field_delete() is correct, the field should now be gone, so when form_builder_field_render() is called the element no longer exists.

This causes drupal_render() in form_builder_field_render() (line 647) to receive a NULL element. This leads to a bad call to uasort in common.inc.

To stop the php error for now, I wrapped the drupal_render in an check on the element:

$content = (is_array($element)) ? drupal_render($element) : '';

My real question is, what is the javascript side of the process expecting back from the remove function, and why is it trying to print an element that has been removed from the cache?

CommentFileSizeAuthor
#2 form_builder_empty_element.patch648 bytesquicksketch

Comments

cdale’s picture

Version: 6.x-0.6 » 6.x-1.x-dev

I just hit this as well. Seems that form_builder_get_element() in api.inc returns FALSE, and should maybe return an empty array()? This would stop things from breaking. Other options could include checking the element which is loaded (and apparently not used) in form_builder_field_json() and checking if it is empty, and not calling form_builder_field_render() on it, or it could be checked as suggested above, just before the render is called.

I'm not sure which is the best or most desired approach.

quicksketch’s picture

Status: Active » Fixed
StatusFileSize
new648 bytes

Thanks guys, I'm not even sure if this is still an issue (it may have been corrected on the JS side), but in any case I've committed this patch (a year later) that implements your suggested fix. If the element is empty, Form Builder does not attempt to render it.

Status: Fixed » Closed (fixed)

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