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.