We've written some custom module code to AJAXify Webforms using Drupal 7's new #ajax actions.

There's one small snag with the forms though. We're returning the form element for processing when it does not validate, and the form is rendered and returned to the client. This works well for everything except for components that require additional processing (using #process callbacks, e.g. webform_expand_select_ids, webform_expand_checkboxes). When the form is submitted via AJAX, Drupal isn't loading Webform's component includes so it cannot find the callback functions.

To get around this, I've added code to the core form.inc to load the component's include file so form_builder() has access to it, which obviously isn't the best way to achieve this. This allows checkboxes/selects to be rendered properly at least.

function form_builder($form_id, &$element, &$form_state) {
    if (module_exists('webform')) {
        module_load_include('inc', 'webform', 'components/select');


Is there a way to force Drupal to load a required module when using the AJAX system?

I've used the steps outlined at http://envisioninteractive.com/drupal/add-ajax-to-a-webform-in-drupal-7/ which works well, except for these few issues.

1 Answer 1


There is the form_load_include() function that is invoked during the initial form build and before form_builder(). You can include this in a hook_form_alter().


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.