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
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 1296362-ajax-error-in-element-validate.patch | 1.05 KB | mfdeveloper |
| #4 | themes.zip | 485.88 KB | pwaterz |
Comments
Comment #1
pwaterz commentedAlso, 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.
Comment #2
catchHave 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.
Comment #3
pwaterz commentedIt 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.
Comment #4
pwaterz commentedmy 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.
Comment #5
pwaterz commentedI 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.
Comment #6
pwaterz commentedComment #7
rfayThis is not a drupal core bug.
You will need to require_once() the file in which alpha_theme_settings_validate_not_empty() is defined.
Comment #8
pwaterz commentedThere 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.
Comment #9
rfayCan 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?)
Comment #10
pwaterz commentedWill do. Yes I did promote it http://drupal.org/project/color_save_custom
Comment #11
pwaterz commentedHey 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.
Comment #12
tinarey commentedHi 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...
Comment #13
dropletz commented+1 subscribing
Comment #14
JaakkoL commentedSame 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
Comment #15
mstrelan commentedSame 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.
Comment #16
cweagansSupport requests are never major or critical.
Comment #17
danielb commentedTry using
http://api.drupal.org/api/drupal/includes!form.inc/function/form_load_in...
Comment #18
alisamar commentedI'm totally stuck due to this problem. I'm looking for a solution.
+1 subscribing
Comment #19
alisamar commentedWhy doesn't anyone care about this issue?Comment #20
mfdeveloper commentedI 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:
However, include file for execute the callback that will not used, it's strange. So, a created a simple patch with a simple test:
For apply the patch, use git am command.