Drupal 7.19
AT 7.x-3.1

When adding an AJAX callback to a form element in theme-settings.php, I get the following error when submitting the form or triggering the AJAX.

Fatal error: Call to undefined function at_core_settings_validate() in /includes/form.inc on line 1464

Here is the form element I'm adding.

...

$form['at-settings']['test_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Test fieldset'),
  );

  $form['at-settings']['test_fieldset']['test'] = array(
    '#type' => 'checkbox',
     '#title' => t('test'),
     '#ajax' => array(
       'callback' => 'test_callback',
       'wrapper' => 'test-wrapper',
       'method' => 'replace',
     ),
  );

  $form['at-settings']['test_fieldset']['test_wrapper'] = array(
    '#type' => 'markup',
    '#markup' => '<div id="test-wrapper">No</div>'
  );
} // End themename_form_system_theme_settings_alter()

function test_callback($form, $form_state) {
  return 'yes';
}

This code works fine in Garland and other themes. Any help would be appreciated. Thanks much.

Comments

Jeff Burnz’s picture

Hmmm, not sure, try explicitly including the function:

require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.validate.inc');

AT calls a custom validation and submit function:

  // Include custom form validation and submit functions
  require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.validate.inc');
  require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.submit.inc');

  // Custom validate and submit functions
  $form['#validate'][] = 'at_core_settings_validate';
  $form['#submit'][] = 'at_core_settings_submit';
richardbporter’s picture

That didn't work for me. Can you reproduce this or is it just something I'm doing wrong?

Not sure if the call stack would help, but ...

 Fatal error: Call to undefined function at_core_settings_validate() in /includes/form.inc on line 1464
Call Stack
#	Time	Memory	Function	Location
1	0.0017	707656	{main}( )	../index.php:0
2	0.2916	41360888	menu_execute_active_handler( )	../index.php:21
3	0.2981	42610360	call_user_func_array ( )	../menu.inc:517
4	0.2981	42610784	drupal_get_form( )	../menu.inc:0
5	0.2981	42611808	drupal_build_form( )	../form.inc:131
6	0.3019	43079416	drupal_process_form( )	../form.inc:374
7	0.5110	45654528	drupal_validate_form( )	../form.inc:846
8	0.5111	45655184	_form_validate( )	../form.inc:1134
9	0.5832	45723184	form_execute_handlers( )	../form.inc:1404

Thanks again.

Jeff Burnz’s picture

I haven't had time to test this, I keep meaning to but time is such a premium at the moment.

alisamar’s picture

This Drupal core bug has been reported before. http://drupal.org/node/1296362 No progress yet

richardbporter’s picture

Thanks for the info.

vvvi’s picture

Issue summary: View changes

I got that error when used a 'managed_file' form element in hook_form_system_theme_settings_alter(). Resolved by adding:

function hook_form_system_theme_settings_alter(&$form, &$form_state) {   
  ... 
  $form_state['build_info']['files'][] = drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.validate.inc';
  $form_state['build_info']['files'][] = drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.submit.inc';
}
Chipie’s picture

@VVVi: Thanks for sharing this. It solved my problem.