After my form is validated wrong and I am returned to the form, when I try to select any term in the Hierarchical Select, the select box is broken. What I saw so far is tht the function hierarchical_select_json when calling cache_get is returning 0. It seems that the user->cache is newer than $cache->created for my $hs_form_build_id.
Anyone having this issue or knowing how to fix it?
Thanks,

Matias.

Comments

wim leers’s picture

Priority: Normal » Minor
Status: Active » Postponed (maintainer needs more info)

Can you reproduce this on a vanilla Drupal installation (i.e. with only Hierarchical Select, Taxonomy and Hierarchical Select Taxonomy)?
And you're sure this is happening on Drupal 5, not on Drupal 6?

mburak’s picture

Yes, it's a Drupal 5. I just did that in a new Drupal installation and I got the same issue. I've created a testing site for you to see it in action. Go here: http://tintasoft.dyndns.org/testHS - User: admin pass: 12345678
Please see it by your self.
Hope this helps!

wim leers’s picture

Title: Hierarchical Select broken on validation » Hierarchical Select broken after validation errors on the form
Version: 5.x-3.x-dev » 6.x-3.x-dev
Priority: Minor » Critical
Status: Postponed (maintainer needs more info) » Active

Reproduced on D6 too now. So this is a bug in both the D6 and D5 versions. I'd swear I've fixed this once before already …

crea’s picture

I researched it while I was finding out if it was a problem with CT integration. This bug happens because during form validation you increase HSID value, but not the $hs_form_build_id value, and you still use old cache. Later in hierarchical_select_json() you are trying to access cached value for new HSID key, but it doesn't exist yet since you haven't update cache and cache contains old HSID key.

wim leers’s picture

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Active » Fixed
wim leers’s picture

Assigned: Unassigned » wim leers
Status: Active » Fixed
braindrift’s picture

Hi,

could someone discribe me, how to apply this patch. I use the version 6.x-3.x-dev from 5 Aug with the patch form http://drupal.org/node/342992#comment-1925006. I still have the issue, although the patch seems to be applied. Im am patching over EclipsePHP and it shows me a Text Comeration Error. I looked into the sources and it seems to have the patch applied. Do I something wrong?

Thanks

braindrift’s picture

Status: Fixed » Needs review
wim leers’s picture

Status: Needs review » Fixed
braindrift’s picture

:)

I know how to apply a patch. But this patch is already in the dev-version from 5 Aug (or not?).

In my hierarchical_select.module is already the code, that this pach is trying to insert.

I STIL HAVE THE ISSUE!!!

braindrift’s picture

Status: Fixed » Active
wim leers’s picture

Assigned: Unassigned » wim leers

I committed the fix on August 15. Clearly, that patch cannot be in the development snapshot of August 5 then. I suspect you didn't apply the patch properly.

braindrift’s picture

Thanks.

In #6 was an other link!

Now you have changed this. I could not find the corect patch and I thought you meen the patch from http://drupal.org/node/528160.

Now I can try the corect patch, Thanks.

braindrift’s picture

Hallo Wim,

I'm sorry, but after applying the patch from #6 nothing changed. I still get this 'Received an invalid response from the server.'-error and after changing the page i get the 'warning: uasort() [function.uasort]: The argument should be an array in /Applications/MAMP/htdocs/drupal-dev-3/includes/common.inc on line 2843.'

I'm sure, that I applied the patch correctly. I see the changes in the code.

Thanks,
dendie

braindrift’s picture

Status: Fixed » Needs work
wim leers’s picture

Status: Needs work » Fixed

Simply do a CVS checkout and you'll get the latest version. No need to patch then. I should have said that the first time because I didn't post the patch. Which I otherwise always do, except for this once because the patch was so simple.

eugenmayer’s picture

StatusFileSize
new4.61 KB

ignore the file, wrong project :)

braindrift’s picture

Status: Fixed » Needs work

OK, I have checked it out from the CVS and I still have the issue. So what should I do now?

wim leers’s picture

Create a screencast of the problem on a vanilla Drupal installation. That is the easiest way to show me the exact steps to reproduce this.

If you don't have any screencasting software already, I'd recommend Jing, which is free.

braindrift’s picture

StatusFileSize
new51 KB
new63.11 KB
new86.16 KB
new107.7 KB
new49 KB
new106.31 KB
new164.12 KB
new122.77 KB
new146.65 KB

Plain instalation with activated Hierarchical Select and Hierarchical Select Taxonomy. Version CVS from 1 hour ago. Drupal 6.13

pic1: Vocabulary Counties (should be Countries ;-) )
pic2: My Content Types
pic3-pic5: Configuration of vocabulary Counties
pic6: Creation of a node (type: Test for HS)
pic7: after clicking Save without entering a Title (to cause a validation error)
pic8: after this validatio error I try to select a Term from the Dropbox and get the 'Received an invalid response from the server.'-error
pic9: after clicking on the menue-item Create content->Test for HS

I hope this can help you to reproduce the error.

Thanks

dendie

mburak’s picture

I'm still having the issue after validation in Drupal 5 with the latest CVS version.

wim leers’s picture

The patch was against D5. I guess I have to backport it. I though it did work in D5.

wim leers’s picture

Version: 6.x-3.x-dev » 5.x-3.x-dev

Double post.

digi24’s picture

I am also still experiencing this issue in D6.

My problem is that the $storage variable in function hierarchical_select_json is not sufficiently filled after a validation error or selecting preview.

Update: digging deeper, I do not really understand it. I do see the cache being created, but the cache_get is somehow empty. Also the cache gets deleted quite often, it does not live for 6 hours, even when I comment clear_cache...

Update2: As far as I understand, whenever the page is submitted or validated, we have a POST request. But this POST request does not contain the hsid variable, so the session value increases.

digi24’s picture

Ok, I have really tried, but for the time being I have disabled the session hsid increase mechanism and I will use only one HS per form.

Then a stupid question, I am not familiar with FAPI: Shouldn't we be rather using hidden instead of value to retrieve the variable? (I could not find it in the POST contents when clicking submit or preview)

-  $element['hsid'] = array('#type' => 'value', '#value' => $hsid);
+  $element['hsid'] = array('#type' => 'hidden', '#value' => $hsid);
grendzy’s picture

I'm also seeing this in the current D6 dev version. To test, I'm submitting a page with no title, then trying to use the menu chooser. There's a popup saying "Received an invalid response from the server."

The message in the log is

Location	/hierarchical_select_json?
Referrer	/node/add/page
Message	uasort() [<a href='function.uasort'>function.uasort</a>]: The argument should be an array in drupal/includes/common.inc on line 2843.
ari-meetai’s picture

OK, did my own dirty work and solved it like this:

/**
 * Hierarchical select form element type #process callback.
 */
function hierarchical_select_process($element, $edit, $form_state, $form) {
	$post_value = $element['#post'][$element['#parents'][0]][$element['#parents'][1]][hsid]; 
	if (is_null($post_value)) {
    // The HSID is stored in the session, to allow for multiple Hierarchical
    // Select form items on the same page of which at least one is added through
    // AHAH. A normal static variable won't do in this case, because then at
    // least two Hierarchical Select form items will have HSID 0, because they
    // are generated in different requests, both of which will have a first HSID
    // of 0. This will then cause problems on the page. 
    if (!isset($_SESSION['hsid'])) {
      $_SESSION['hsid'] = 0;
    }
    else {
      // Let the HSID go from 0 to 99, then start over. Larger numbers are
      // pointless: who's going to use more than a hundred Hierarchical Select
      // form items on the same page?
      $_SESSION['hsid'] = ($_SESSION['hsid'] + 1) % 100;
    }
    $hsid = $_SESSION['hsid'];	
  }
  else {
  	$hsid = $post_value;
  }
 $element['hsid'] = array('#type' => 'hidden', '#value' => $hsid);

Works for two HS in the same form too.

I'm on D6, don't know how it would work on D5.

Hope it helps.

Cheers.

slip’s picture

StatusFileSize
new1.91 KB

Hey guys,

I tried arielon's patch and it worked for me, although I didn't spend much time trying to figure out the problem. I'll keep testing the patch as I build the site, but so far it's looking good.

I rolled it into a patch for drupal 6 CVS head so people can see what it does better and apply it themselves.

grendzy’s picture

Status: Needs work » Reviewed & tested by the community

#29 worked for me. Thanks!

digi24’s picture

Status: Reviewed & tested by the community » Needs work

Arielon and Slip, it seems that there are some quotes missing in the last part of your post_value definition.

wim leers’s picture

Status: Needs work » Fixed

This was fixed as a side effect of the patch for #574244: Hierarchial Select + Views + AJAX enabled :)

braindrift’s picture

Status: Fixed » Needs work
StatusFileSize
new19.39 KB

Hi,

sorry but after I applied this patch I got the box with the message:"You don't have Javascript enabled."

What am I doing wrong?

braindrift’s picture

There goes something wrong after refreshing the node-creation form. When I try to create the node directly after login, there is no issue. But after refreshing the page I get this box.

To get this box away, I have to logout and login again. This indicates a problem with the session (the box appears if the hsid in the session is >0).

wim leers’s picture

Status: Needs work » Postponed (maintainer needs more info)

Weird, I cannot reproduce that, dendie. Can you reproduce that on a vanilla installation? Does it happen in all browsers?

braindrift’s picture

StatusFileSize
new130.92 KB
new144.31 KB
new166.4 KB
new123.51 KB
new156.84 KB
new224.4 KB
new185.83 KB

I just reproduced it on a vanilla instalation with only HS-module available.

Yes, it happens in all browsers.

With the session-viewer (devel) I see, that as long as the hsid is 0, HS works fine. As soon as hsid becomes 1 ore more there appears this box.

Explanations for the pictures:
1: Vanilla Instalation with HS
2: Test-vocabulary for HS enabled vor content type "Test4hs"
3: Terms of the testvocabulary
4: Trying to create Test4hs (the box is there)
5: Logout
6: Trying to create Test4hs after login (the box is gone)
7: After refreshing the page (the box is there)

braindrift’s picture

Status: Postponed (maintainer needs more info) » Needs work
ari-meetai’s picture

Wim Leers - September 21, 2009 - 13:06
Status: needs work » fixed

This was fixed as a side effect of the patch for #574244: Hierarchial Select + Views + AJAX enabled :)

Oh, I didn't find that in time.. Anyway, it was fairly difficult to sort the patch+install version order...

Kudos for the great module!

wim leers’s picture

Status: Needs work » Postponed (maintainer needs more info)

dendie: I followed your steps exactly and cannot reproduce the problem …

braindrift’s picture

The patch seems not to work with "Hierarchical Select Menu". As soon as I disabled this module, the box was gone.

@Wim: Could you please try to reproduce this.

Thanks
dendie

braindrift’s picture

Version: 5.x-3.x-dev » 6.x-3.x-dev
Status: Postponed (maintainer needs more info) » Needs work
wim leers’s picture

Title: Hierarchical Select broken after validation errors on the form » Hierarchical Select breaks with >1 Hierarchical Select form item on the page
Status: Needs work » Active

That's it! Now I can reproduce it. I'll look into this tomorrow. I'm fairly sure it's caused by #574244: Hierarchial Select + Views + AJAX enabled though — as you had already indicated.

Thanks for persisting! :)

wim leers’s picture

Status: Active » Fixed
StatusFileSize
new962 bytes

Just went ahead and fixed it right away.

I couldn't reproduce the problem in Drupal 5, so I'm assuming it's due to a very specific, minor, internal difference between the Drupal 5 and Drupal 6 Forms APIs.

Please confirm that the problem has been fixed. Either update to CVS HEAD or apply the attached patch.

braindrift’s picture

Hello Wim,

that's great. it seems to work now.

Thanks for this quick patch!

dendie

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.