So I know there is a similar issue in the issue queue that was closed a while ago, but it didn't really seem to have a fix for my situation, at least not that I could understand. I basically am using ThemeKey in a specific part of my site which also contains a custom form that I created using the Drupal form API in a custom module. This form takes an email address first and then the submit is done via AJAX and it returns information based off of the email address in a modification of the same form. The problem is when you first come to the page, the theme switches correctly, but when you submit the form via AJAX, the whole page switches and you get this weird blend of the default site template and the theme it is supposed to be switching to so the page is all messed up. OH and this only happens when the user is not logged in. If they are logged in, it works as expected. Is there an easy fix for this or am I to just not use AJAX with ThemeKey? Any help would be GREATLY appreciated.

THANKS!

CommentFileSizeAuthor
#9 themekey2.PNG30.96 KBSoCalErich
#6 themekey.PNG74.14 KBSoCalErich
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SoCalErich’s picture

Issue summary: View changes
mkalkbrenner’s picture

Are you using the AJAX functionality the drupal core provides or did you implement something by yourself?
Did you configure /admin/config/user-interface/themekey/settings/ajax?
Do you use method POST when submitting the form using AJAX?
Does your POST contain $_POST['ajax_page_state']['theme'] and $_POST['ajax_page_state']['theme_token']?

getsuresh401’s picture

@mkalkbrenner: No, I didn't do any changes in themekey/settings/ajax. I found that there it has two options selected
1. Use current theme for Ajax responses.
2. Always consider the default theme to be safe.
Does this is causing this issue.

My requirement:
1. when anonymous or authenticated user visits, 'default' theme will be shown. user with role admin will be shown 'Admin' theme.
2. when a user with role 'Editor' logs in, he should be show with 'Admin' theme. This is successfully achieved. but when he try to edit something he is taken to 'default' theme. I want to have Admin theme for this user role.

getsuresh401’s picture

I unchecked those and found that the problem is still exist in following admin pages:
'/admin/people/create',
'/user/17/edit',
admin/people/create',
'admin/structure/menu/manage/main-menu'

when the user having user role 'Editor' visit the above pages, then the theme changes to default one. Rest of the pages are fine.

mkalkbrenner’s picture

@getsuresh401
Why are you commenting this issue? My questions from #2 need to be answered by erich93063 regarding this issue and are not related to #2227835: issue with theme change of a perticular user-role in any way!

SoCalErich’s picture

FileSize
74.14 KB

Thank you for your quick reply.

Are you using the AJAX functionality the drupal core provides or did you implement something by yourself?
I am using Drupals built in AJAX functionality by simply specifying the #ajax parameter on my submit button and nothing more.

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit'),
  '#attributes' => array('class' => array('submit')),
  '#ajax' => array(
    'callback' => '_display_form',
    'wrapper' => 'ajax_wrapper',
    'effect' => 'fade',
    'event' => 'click',
  ),
);

Did you configure /admin/config/user-interface/themekey/settings/ajax?
I noticed in the docs that it mentioned something about some AJAX settings, but I do not see them anywhere in my ThemeKey settings. I looked everywhere. I went to the above URL you provided and I do not see any AJAX settings. I took a screenshot and attached it to this post for you to see what I get when I go to that URL you provided.

Do you use method POST when submitting the form using AJAX?
I am using what Drupal uses by default when specifying the #ajax parameter on a submit button, which yes is POST.

Does your POST contain $_POST['ajax_page_state']['theme'] and $_POST['ajax_page_state']['theme_token']?
I'm not sure how to verify this. I am not specifying these things in my code anywhere. Should I be? If so, I'm not sure how. Since this is an AJAX submit, I'm not sure how to verify those values exist upon post.

Thank you for your help!

mkalkbrenner’s picture

Status: Active » Needs review

You need to update ThemeKey to 7.x-3.0. This is the first version that supports the core ajax form stuff. After the update you'll be able to access the settings.
Sorry, I didn't notice the Version number when I wrote comment #2.

SoCalErich’s picture

Sweet, that's what I was actually going to try next anyway. I'll update and report back. THANKS!!

SoCalErich’s picture

FileSize
30.96 KB

Arg. So it's still not working after the update. I even tried disabling and uninstalling and then re installing v3.0 and reapplying my rule chain (and clearing cache), but when a user is not logged in, they get the mixed theme after AJAX submit. I uploaded a screenshot of what my AJAX settings are set to.

mkalkbrenner’s picture

Try the "Bypass" option and set your themes as safe themes.

SoCalErich’s picture

Still happening with the Bypass option checked and all themes set to safe. :-/

SoCalErich’s picture

So I decided to try something. I completely disabled ThemeKey and added the following code to my custom module:

function job_agent_custom_theme() {
  if (arg(0) == 'vista') {
    return 'vista';
  }
}

This did exactly what I was trying to accomplish with ThemeKey and switched my theme to a custom theme based on the URL. The funny thing is I have the EXACT same problem I had with ThemeKey and ThemeKey is completely disabled, so it's not a ThemeKey issue, but a Drupal issue. I'm still in the same boat though and don't know how to fix it, but thought that was interesting.

mkalkbrenner’s picture

If you use page cahcing and want to offer your feature to anonymous users, you'll need ThemeKey which should work around the known core issues with ajax forms.

But we need to find out what is going on on your site.

Can you dump the $_POST values of this AJAX request?
What's the destination URL of the AJAX request?
Can you post your ThemeKey rules here?

SoCalErich’s picture

Whats the best way to dump those variables? Since it is an AJAX post when I do a print_r($_POST) in my form submit method, I just get a JavaScript alert box that has a TON of variables in it so much so that it goes off the bottom of the screen and there is no way to read it all because there is no way to scroll the alert box.

SoCalErich’s picture

Or I can dump specific variables then if you want to make it shorter and more readable. ??

Also for the other questions:

The destination URL is the same as the original form. The submit is just posting to the same form and I am then modifying the form that gets rebuilt filling in data from the database based on the email address.

And my ThemeKey rule is very basic. I actually only have one for this specific need and it is :

drupal:path = vista/job-alerts which will change the theme to "vista"

mkalkbrenner’s picture

Maybe we just fixed what causes your issue:
#2232571: ajax forms still return mixed themes

Can you give it a try?

SoCalErich’s picture

SWEET! I installed the themekey-7.x-3.x-dev version and it fixed the issue! Thanks so much for taking the time to look at this. Much appreciated.

mkalkbrenner’s picture

Status: Needs review » Closed (duplicate)

You're welcome!