Ajaxifying a set of radio buttons causes the following error when a radio button is selected:

PHP Fatal error:  Call to undefined function webform_expand_select_ids() in /home/wwwroot/myproject/public/includes/form.inc on line 1724, referer: http://myproject/ajax-test

I assume webform_expand_select_ids() is not in scope when the ajax request is being processed.

Here's the hooks used to setup ajax on the radio buttons:

/**
 * Implementation of hook_form_FORM_ID_alter().
 *
 */
function custom_form_webform_client_form_32_alter(&$form, &$form_state, $form_id) {
  $form['submitted']['choice']['#ajax'] = array(
      'wrapper' => 'webform-component-options',
      'callback' => 'custom_switch_fields_callback',
    );
}

function custom_switch_fields_callback($form, $form_state) {
  return '<strong>new output</strong>';
}

Changing the radio buttons to a select list fixes the problem as webform_expand_select_ids() processing is used for radio buttons and checkboxes only.

Comments

nsciacca’s picture

Getting similar error for checkboxes:

Fatal error: Call to undefined function webform_expand_checkboxes() in /Users/nicole/Sites/dev1/includes/form.inc on line 1724

hooks:

/* Implementation of hook_form_alter() */
function dev1_mod_form_alter(&$form, &$form_state, $form_id) {
	if ($form_id == 'webform_client_form_5') {
		$form['actions']['submit']['#ajax'] = array(
		      'callback' => 'dev1_mod_submit_form_js',
		      'wrapper' => 'webform-component-result',
		      'method' => 'replace',
		      'effect' => 'fade',
		 );
	}
	
}


/* function to handle ajax submission */
function dev1_mod_submit_form_js($form, $form_state) {
	return 'test';
}
quicksketch’s picture

Category: bug » support
Status: Active » Closed (fixed)

Support on custom coding is not provided in the Webform queue.

ardnet’s picture

Status: Closed (fixed) » Active

Hi quicksketch,
sorry I open again this issue.

I came across this thread when I try to debug my problem ( http://drupal.org/node/1211320 )
Turns out I got same problem like bluehut and nsciacca.
I want still to use radio button for my webform, instead of changing to select list.

And you mentioned that support on custom coding is not provided in Webform queue, sorry what's that means?
Do you have some way how to solve this kind of issue?

Thanks in advance.

quicksketch’s picture

Status: Active » Closed (won't fix)

And you mentioned that support on custom coding is not provided in Webform queue, sorry what's that means?

I'm happy to provide support on how to use Webform through the UI and fix bugs, but I don't provide support on questions about writing code.

yannisc’s picture

I got the same error: Fatal error: Call to undefined function webform_expand_checkboxes() in includes/form.inc on line 1748

nchar’s picture

The problem occurs when we have a multi page form (3 pages) and the first two pages have at least a checkbox while the last one doesn't. So the error: "Fatal error: Call to undefined function webform_expand_checkboxes() in includes/form.inc on line 1748" appears at the last page...

The problem happens because the file "componens/select.inc" is not loaded at the last page, as there is no checkbox component, but "webform_expand_checkboxes" function, which is defined in "select.inc", is called by "form_builder" in form.inc as a process;

So i think that either:

-all functions named "webform_expand_something" should be moved in webform.module so they can be accessible at anytime,
-or all components of the whole form should be included in every page... In this case the "_webform_client_form_rule_check" function should be removed.

quicksketch’s picture

Thanks @ncharalampidis, I've taken your description and posted it to the new issue at #1332100: Prevent undefined function calls in component includes. If this indeed can be reproduced out-of-box it should be a bug report.

Bcwald’s picture

-all functions named "webform_expand_something" should be moved in webform.module so they can be accessible at anytime,

I can confirm that this does work. Moving both functions: webform_expand_checkboxes (I didnt have checkboxes but radio buttons) and also webform_expand_select_ids into the webform.module fixed this problem..

I think this is not the best method, but I wanted to confirm that accessibility in the node_load is the issue.

Also, I will mention that this doesn't only happen on a multi page form.. Mine was only a single page form.

cangeceiro’s picture

I am also running into this error when using ajaxified webforms. Even though my instance and a few others are using custom code, this looks like its creeping into other areas as well that are not related to custom code. Is there any plan to treat this as an actual bug and not just a support request for custom code?

grayb’s picture

Status: Closed (won't fix) » Active

No custom code, but I'm using multipage form and seeing this problem.

bartclarkson’s picture

I think we need to make the "without hacking webform module" solve clear to people searching for a magic snippet. Like me.

So adding to SweetCircus comment: the basic upshot at this point in time is that, in the custom module ("dev1_mod", respective to comment 1), you need the following lines of code:

require_once drupal_get_path('module', 'webform') . '/components/date.inc';
require_once drupal_get_path('module', 'webform') . '/components/grid.inc';
require_once drupal_get_path('module', 'webform') . '/components/time.inc';
require_once drupal_get_path('module', 'webform') . '/components/select.inc';

If you want the whole custom module code (webform_ajax_submit.module), it follows. Special thanks to Envision (http://envisioninteractive.com/drupal/add-ajax-to-a-webform-in-drupal-7/)


function webform_ajax_submit_init() {
  require_once drupal_get_path('module', 'webform') . '/components/date.inc';
  require_once drupal_get_path('module', 'webform') . '/components/grid.inc';
  require_once drupal_get_path('module', 'webform') . '/components/time.inc';
  require_once drupal_get_path('module', 'webform') . '/components/select.inc';
}

function webform_ajax_submit_form_alter(&$form, &$form_state, $form_id) {
  // see if webform_client_form_ is in the form_id
  if(strstr($form_id, 'webform_client_form_')) {
    // get the nid so we can use it in the wrapper value
    $nid = $form['#node']->nid;
    // add the ajax properties to the submit button
    $form['actions']['submit']['#ajax'] = array(
      'callback' => 'webform_ajax_submit_webform_js_submit',
      'wrapper' => 'webform-client-form-' . $nid,
      'method' => 'replace',
      'effect' => 'fade',
    );
  }
}
 
function webform_ajax_submit_webform_js_submit($form, $form_state) {
  // define the $sid variable (submission id from webform)
  $sid = $form_state['values']['details']['sid'];
  // if we have a sid then we know the form was properly submitted, otherwise, we'll just return the existing $form array
  if ($sid) {
    // first we have to load up the webform node object
    $node = node_load($form_state['values']['details']['nid']);
    // create an array up with the confirmation message, retreived from the webform node
    $confirmation = array(
      '#type' => 'markup',
      '#markup' => check_markup($node->webform['confirmation'], $node->webform['confirmation_format'], '', TRUE),
    );
    // return the confirmation message
    return $confirmation;
  }
  else {
    // return the form
    return $form;
  }
}
cangeceiro’s picture

here is how i was able to get around this issue

/*
 * Implements hook_init
 */
function MYMODULE_init() {
    // hack to fix webforms
    if ($_GET['q'] == 'system/ajax' && isset($_POST['form_id'])) {
        foreach (webform_components() as $component_type => $component_info) {
            webform_component_include($component_type);
        }
    }
}
quicksketch’s picture

Status: Active » Closed (fixed)

As a bug, we're handling this in #1332100: Prevent undefined function calls in component includes. This issue is all about custom coding (which happened to reveal the bug).