Hi

I have a Registration form (using Component Profile) with a cck field called Zone (Province, City, etc) and using Hirarchical Select as widget.

All goes OK, the anonymous user select the city and submit the registration form. All fields are saved in the database except the Zone field.

I've tried to debug using _nodeapi and I see that for INSERT operation, the field is empty.

Any idea to solve the problem?

Note:
The field is configured with these options:
-Save term lineage
-Force the user to choose a term from a deepest level

Comments

jibort’s picture

Please, some idea?

Is there any person who had success with a registration form (with content profile) and a CCK field using Hierarchical Select in that registration form? Is this suported?

Thanks

rutiolma’s picture

I managed to resolve this issue for my specific problem.
In my opinion the problem is in the content_profile module. In the folder "modules" under content_profile, there's a "content_profile_registration.module" with a declared function named "content_profile_registration_user_register_submit".
When I print the $node content, I see that the content taxonomy (CT) field isn't formatted the right way to be saved. This CT array, needs to have one or more arrays of numeric values (like [0], [1], [2] etc) and inside each a array called [value] with the CT values.

for example in my case, the $node value outputs:

[field_curso_fct] => Array
                        (
                            [tids] => Array
                                (
                                    [hsid] => 21
                                    [hierarchical_select] => Array
                                        (
                                            [selects] => Array
                                                (
                                                    [0] => 1575
                                                    [1] => 1576
                                                )

                                        )

                                )

                        )

and the work around was putting the following snippet in content_profile_registration_user_register_submit function

      $no = $node->field_curso_fct['tids'];
      foreach($no as $key=>$value){
      	$node->field_curso_fct[$key]['value'] = $value;
      }

Cause the lack of time, I cannot provide a patch neither a generic workaround (maybe in the future), but I hope it helps.

jibort’s picture

although it is a very very specific solution, it really works! thanks!

Try to find out why these areas are badly formatted. More than Content Profile, do not you think that could be a problem specific to the Hierarchical Select module?

Thank you very much!

lcollet’s picture

Hello,

I didn't set a patch but this following code should help to not set hard coded values.

This code snippet should be placed in the content_profile_registration_user_register_submit method just before the node submition.

      if ( module_exists( "hierarchical_select" ) )
      {
        $query = "SELECT distinct field_name, multiple FROM {content_node_field_instance}
          INNER JOIN {content_node_field} USING (field_name)
          WHERE type_name = '{$type}' AND widget_type LIKE '%_hs'";
        $db_result = db_query( $query );

        //We look for all fields
        while( $item = db_fetch_array( $db_result ) ) {
          $field_name = $item['field_name'];
          $val = array();
          //The intermediary table is necessary ?
          $field_table = $node->$field_name;
          foreach( $field_table as $key => $value ) {
            $val[] = array( 'value' => $value );
          }
          $node->$field_name = $val;
        }
      }

It is working fine with single fields, I didn't tested with mutliple ones.

Hope this helps.

Wim Leers’s picture

Priority: Normal » Minor
Status: Active » Needs work

So basically this is once again an epic Content Taxonomy fail. I'm so sick of Content Taxonomy. I won't spend any more minute in that code. I'll accept a patch, but I won't support it myself.

sifaan’s picture

err... sorry if this is a lame newbie question; but what are the alternatives to using Content Taxonomy if I want to use HS with CCK/Views?

Wim Leers’s picture

Status: Needs work » Closed (won't fix)

There are none. Content Taxonomy is just a fragile piece of shit that most of us try to avoid as much as possible. In D7, there is a Taxonomy field in core and this will no longer be an issue :)

Just use core's Taxonomy in D6.

ilsodas’s picture

Status: Closed (won't fix) » Active

a

ilsodas’s picture

Title: HS on registration form does not save values » Bible
Project: Hierarchical Select » Subscribe
Version: 6.x-3.1 » master
Component: Code - Content Taxonomy » Miscellaneous
Status: Active » Closed (won't fix)
jvandyk’s picture

Title: Bible » HS on registration form does not save values
Project: Subscribe » Hierarchical Select
Version: master » 6.x-3.1
Component: Miscellaneous » Code - Content Taxonomy
gabor_h’s picture

Hi,

Here is an improved version of #4. It seems to work with multiple fields, too.

      if (module_exists("hierarchical_select"))
      {
        $query = "SELECT distinct field_name, multiple FROM {content_node_field_instance}
          INNER JOIN {content_node_field} USING (field_name)
          WHERE type_name = '{$type}' AND widget_type LIKE '%_hs'";
        $db_result = db_query($query);

        //We look for all fields
        while ($item = db_fetch_array($db_result)) {
          $field_name = $item['field_name'];
          $val = array();
          $field_table = $node->$field_name;
          foreach ($field_table['tids'] as $key => $value) {
              $val[] = array('value' => $value);
          }
          $node->$field_name = $val;
        }
      }

The instructions, again:
The content_profile module contains the "modules" folder which contains the "content_profile_registration.module" file which contains the "content_profile_registration_user_register_submit" function . This code snippet should be placed in the content_profile_registration_user_register_submit method just before the "Create the node" and "node_submit($node)" lines.

samuelet’s picture

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

It's working for me.
Should this issue be moved into the Content Taxonomy project?

Balbo’s picture

I got this warning on my test site:

# warning: Invalid argument supplied for foreach() in .../sites/all/modules/content_profile/modules/content_profile_registration.module on line 269.

Line 269 is the foreach ($field_table['tids'] as $key => $value) {.

I'm not sure what the snippet is about and would appreciate any help. I think the error it's related to the other module I'm using which is http://drupal.org/project/hs_nodereference.

Balbo’s picture

Ok. I did some changes in the code so you can use it if you are using Hierarchical Select and Hierarchical Select Node Reference with Content Taxonomy.

if (module_exists("hierarchical_select")){
	$query = "SELECT distinct field_name, multiple FROM {content_node_field_instance}
			INNER JOIN {content_node_field} USING (field_name)
			WHERE type_name = '{$type}' AND widget_type LIKE '%_hs'";
	$db_result = db_query($query);

	//We look for all fields
	while ($item = db_fetch_array($db_result)) {
	$field_name = $item['field_name'];
	$val = array();
	$field_table = $node->$field_name;

	if (isset($field_table['tids'])){
		foreach ($field_table['tids'] as $key => $value) {
			$val[] = array('value' => $value);
		}
	}

	if (isset($field_table['nid'])){
		foreach ($field_table['nid'] as $key => $value) {
			$val[] = array('nid' => $value);
		}
	}

	if (!empty($val)){
		$node->$field_name = $val;
	}
}

It's working for me, but please take a look at it and tell the community if you find it not to be correct or safe.

mandclu’s picture

#11 worked for me (I'm not using Hierarchical Select Node Reference).

kenorb’s picture

Status: Closed (won't fix) » Closed (duplicate)
feuillet’s picture

#11 works like a charm here. Thanks!

arski’s picture

why on earth was this post closed and the #944788: Values not saved when used in registration with Hierarchical Select kept open?? after all, it is this one that provides possible solutions! :O

arski’s picture

Status: Closed (duplicate) » Needs work

and btw +1 on the fix, looks good. How about you create a real patch so that we can at least try and get it committed?

Kcannick’s picture

I'm having the same error "Invalid argument supplied for foreach() in .../modules/content_profile/modules/content_profile_registration.module on line 269" however I am not using the node reference field on profile type. Also tried adding the code snippet you posted below with same result.

capellic’s picture

I am having the same issue as reported in #20. I am using the HS field on a profile which is also appearing on the registration form. I am not using it with node reference. There are two other Content Taxonomy fields on the form, but none of them are using HS.

In my case, a value is saved even with the error. But it's not a value from this field, rather it is a taxonomy value from the first content taxonomy field on the form. If the first value in the HS field is selected, it saves the first value of the first Content Taxonomy field on the form.

capellic’s picture

I don't know why my situation is different, but I had to change the 'tids' loop to be this:

foreach ($field_table as $value) {
  $val[] = array('value' => $value);
}
anjjriit’s picture

@ gabor_h #11
Thanks a ton !!!
You save my life, your instruction is very clear.

Keep working!!!

franz’s picture

With my current module versions, the 'tids' is not an array, at least for non-multiple fields, so I changed the snippet (and improved the query to be a little more on standards)

<?php
      if (module_exists("hierarchical_select")) {
        $query = "SELECT distinct field_name, multiple FROM {content_node_field_instance}
                INNER JOIN {content_node_field} USING (field_name)
                WHERE type_name = '%s' AND widget_type LIKE '%%_hs'";
        $db_result = db_query($query, $type);

        //We look for all fields
        while ($item = db_fetch_array($db_result)) {
          $field_name = $item['field_name'];
          $val = array();
          $field_table = $node->$field_name;

          if (isset($field_table['tids'])){
            if (is_array($field_table['tids'])) {
              foreach ($field_table['tids'] as $key => $value) {
                $val[] = array('value' => $value);
              }
            }
            else {
              $val[] = array('value' => $field_table['tids']);
            }
          }

          if (isset($field_table['nid'])){
            foreach ($field_table['nid'] as $key => $value) {
                $val[] = array('nid' => $value);
            }
          }

          if (!empty($val)){
            $node->$field_name = $val;
          }
        }
      }
?>
smakisog’s picture

#24 Work for me. Thx!

wizonesolutions’s picture

Is this only for Content Taxonomy users? I use Content Profile and am hitting the same error. The form also seems to be arranged incorrectly from what HS expects. Is there a version of this fix when using the core taxonomy field in D6 and having selected the Content Profile content type as one of the types for which terms can be selected?

franz’s picture

wizonesolutions, I believe the fixes posted are all related to Content Profile usage on registration. However, I'm unsure if they fix the core taxonomy fields. Maybe you could test or consider using Content Taxonomy on it (which is a great addition).

jordan8037310’s picture

Has anyone else had any more issues with this? Currently having the same issue but the patches are not fixing it.

In my case, this doesn't work when we have one of the hierarchical fields hidden. When both hierarchical menus show it saves fine.

Anyone have a solution for this?

jordan8037310’s picture

In order to fix this issue I had to reset the $form['#uid'] in later executed functions.

I inserted the below code in order to "reset" the Form#uid where it was needed.

        $form['#uid'] = $node->_account->uid;

For my purposes this code was inserted into content_profile_useredit_user_edit_submit()...

Hope this helps others if they have more issues!

Gold’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Tidying up the issue queue. The 6.x version is no longer supported. Only reopen this if it also applies to the 7.x.