Situation:

I am writing a module that will allow you to save custom color profiles to the database. I am doing a hook_form_alter on system_theme_settings and adding a ajax callback to the select list in the color module. Everything work fine when I test it against the Bartik theme. The problem arises when the ajax fires a callback when the system_theme_settings form has a form element with a #element_validate. It try's to call the validate function but the file that it's located in is not included, that file resides in a theme. The theme I am using is an extension of the omega theme and the hook_form_alter is in the omega theme.

Error:
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText: n/a
ResponseText:
Fatal error: Call to undefined function alpha_theme_settings_validate_not_empty() in /..../public_html/includes/form.inc on line 1361
ReadyState: undefined

Comments

pwaterz’s picture

Also, I have been trying to think of work around for this but have no idea how to dynamically load a themes files in a hook_form_alter.

catch’s picture

Status: Active » Postponed (maintainer needs more info)

Have you checked that the ajax callback is even initializing the theme at all? That's not guaranteed.

This needs a test module or ideally a test case.

pwaterz’s picture

It is not initializing the theme. The problem that i see is that when #element_validate is being processed in form.inc it doesnt check if function exists. Is that proper behaviour?

I will upload my module later today.

pwaterz’s picture

StatusFileSize
new485.88 KB

my Color Save Custom sandbox http://drupal.org/sandbox/pwaterz/1296704

I have also attached the theme that I am getting this error against. It's an extension of omega.

Steps to reproduce

1. Enable color, color save custom modules
2. Enable chromega theme
3. Go to chromega theme settings
4. On the color config at the bottom change the 'Color Set' select list to 'Custom' or anything different to trigger the ajax call.

You will get an ajax error about not being able to find a function.

pwaterz’s picture

I was able to figure out a work around by setting $form_state['must_validate'] = false;, and then setting it back to true on my ajax callback. But this caused another problem when submitting the form.

When I submitted the form is said that it could not find one of the submit callbacks in the form alter in the omega theme. I proceded to work around this by making my submit function load first and then dynamically loading theme-settings.php for the current theme and all its sub themes.

I know that this works, but there seem like there is a bug somewhere, unless this is correct behavior.

pwaterz’s picture

Status: Postponed (maintainer needs more info) » Active
rfay’s picture

Category: bug » support
Status: Active » Fixed

This is not a drupal core bug.

You will need to require_once() the file in which alpha_theme_settings_validate_not_empty() is defined.

pwaterz’s picture

Status: Fixed » Active

There still seems to be a bug somewhere.

If you do the following steps you will get an error
1. Hook form alter a form that something in the theme layer is hooking into, and of which adds some sort of callback for validate or submit
2. Then add an ajax callback and wrapper to it.
3. Then just submit the for like normal.
4. You will get files not found errors, but if i remove the ajax form alters, it goes away.

Why does it do this, that seems like a bug.

rfay’s picture

Can you make a super-simple demonstration module that demonstrates the simplest case and put it in a sandbox? I'll try to take a look at it. I'd prefer you demonstrate this with a core theme, but since it seems to require the theme to be altering... (BTW, the module sandbox you linked to above doesn't seem to work. Did you promote it?)

pwaterz’s picture

Will do. Yes I did promote it http://drupal.org/project/color_save_custom

pwaterz’s picture

Hey guys I am still having this problem. It is coming from a hook_form_alter in a theme that sets #element_validate. When the ajax response process I can not figure out a way to include the proper files first before it tries to call an #element_validate function.

I don't have a lot of time to build a example module right now...I will try to soon.

tinarey’s picture

Hi there,
I'm having the same thing: I'm trying to add some ajax powered form settings to an Omega subtheme.
So in theme-settings.php of my subtheme I call hook_form_system_theme_settings_alter() and have a select field with #ajax and callback. (Trying to update some fields according to a preset that can be selected with the ajax-calling select field). Getting the exact same error...

dropletz’s picture

+1 subscribing

JaakkoL’s picture

Same problem here. Trying to add a managed file field to my theme-settings.php. Theme is I subtheme of Omega. The files do get uploaded and the file_managed stores correct data.

Error message:
ResponseText: Fatal error: Call to undefined function alpha_theme_settings_validate_not_empty() in
/includes/form.inc on line 1379

mstrelan’s picture

Same issue occurs if a form is in an include file, as is the validate function, and that module's .info file doesn't reference the include file and another module comes along and adds #ajax to another form element.

cweagans’s picture

Priority: Major » Normal

Support requests are never major or critical.

alisamar’s picture

I'm totally stuck due to this problem. I'm looking for a solution.
+1 subscribing

alisamar’s picture

Why doesn't anyone care about this issue?

mfdeveloper’s picture

Category: support » bug
Status: Active » Patch (to be ported)
Issue tags: +hook_form_alter, +form elements, +ajax error, +ajax callback
StatusFileSize
new1.05 KB

I have the same issue today with Search configuration module, when I created a custom button with #ajax handler. The solution described on #17 comment it's works.

Example:


    //check if module with #element_validate callback on hook_form_alter is enabled
    if(modules_exists('something_module')){

          //Include file with #element_validate callback using this function, instead of module_load_include()
          form_load_include($form_state, 'inc', 'something_module','something_module.admin');
    }

However, include file for execute the callback that will not used, it's strange. So, a created a simple patch with a simple test:


  //file form.inc on _form_validate() function on lines 1411 e 1412
  if(function_exists($function))
            $function($elements, $form_state, $form_state['complete form']);

For apply the patch, use git am command.

Status: Patch (to be ported) » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.