Hi,

I am using the Automatic Nodetitles module to automatically generate a node title based on some CCK-fields. It works as expected for ordinary text fields, but accessing the selected value of a select list always results in an empty string.

Here is the code I use in the Automatic Nodetitles module:

<?php
  global $form_values;
  $node = (array)$form_values;
  $casenumber = $node['field_caseno_type'][0]['value'] . ' ' . $node['field_caseno_seqno'][0]['value'] . '/' . substr($node['field_caseno_year'][0]['value'],-2);
  $headword = $node['field_headword'][0][value];
  if ($headword) {
    print $casenumber . ' - ' . $headword;
  } else {
    print $casenumber;
  }
?>

The fields caseno_seqno and caseno_year are text fields and appear in the node title. The field caseno_type is a select list with text keys. The selected field value is correctly shown in the node itself, but the value does not show up in the node title.

Does anyone have a clue what I am doing wrong here? I suppose I am doing something wrong in accessing the selected value, but I don't know how to make it work correctly.

Thanks,

Mark

Comments

rick24’s picture

I finally got this to work by installing both the Automatic Nodetypes module and the Token module. Then in the CCK data type / Automatic title generation, I set the pattern to "[field_X-raw]", where X is the name of your CCK field. The '-raw' or other flag is evidently required.

If you want to set the title to a selected Taxonomy term, use "[term-raw]". If you have multiple taxonomies, see http://drupal.org/node/210319 .

groenm’s picture

Hi Rick,

Thanks for looking into it. Unfortunately, it is still not working.

I already had the token-module activated. When I use: [field_X], all fields work except the select list (field caseno_type) which outputs an empty string. When I use [field_X-raw] or [field_X-formatted], the result is an empty string for all fields, also the ones that work with [field_X].

I am using Drupal 5.7, CCK 5.x-1.6-1, Automatic Nodetitles 5.x-1.1 and Token 5.x-1.10.

Mark

mooffie’s picture

global $form_values;

You should use $node, not $form_values. CCK, in the 'validation' phase --which is also the phase in which auto_nodetitle operates-- copies the values from the selectbox to the underlying field. But it does this on this same $node object, not on the global $form_values. Do a drupal_set_message(print_r($node,1)) to see what it contains.

You say that tokens don't work. That's bad. It's worth to investigate this.

groenm’s picture

Hi Mooffie,

Thanks for your input. I will give your directions a go in about 2 weeks when I have returned from travelling.

Greetings,
Mark

mooffie’s picture

You should use $node, not $form_values.

It turns out '$node' is not accessible in auto_nodetitle's PHP pattern. I've just reported this and provided a patch.

I already had the token-module activated. When I use: [field_X], all fields work except the select list

You're saying that tokens don't work for you. I've just tried this and they do work for select lists.

However, I did find another user that complained that tokens for select lists don't work for him:
http://drupal.org/node/176491

Could you try disabling all modules you can and see if the problem persists?

Also, could you check the 'weight' of the 'auto_nodetitle' module in your {system} table? It should be '5'.

groenm’s picture

Hi Mooffie,

Thanks for investigating.

Interesting that somebody else experienced this too. Before posting I did some searching on select list, but did not find his post.

I found some time to set up a copy of my drupal database for a test. (Runs off the same server and same code base as my production site.)

I disabled almost all modules. I left these enabled:

Core optional:

  • menu
  • path

CCK:

  • Computed Field
  • Content
  • Field Group
  • Number
  • Option Wigdets
  • Text

Other:

  • Automatic Nodetitles
  • Pathauto
  • Token

Result
The same as before. Token is still not working. The field with the select list stays blank in Automatic Nodetitles. The other fields work without '-raw' or '-formatted', however, with '-raw' or '-formatted', they blank too as before.

As for the weight of Automatic Nodetitles:

mysql> select name, weight from system where name='auto_nodetitle';
+----------------+--------+
| name           | weight |
+----------------+--------+
| auto_nodetitle |      5 |
+----------------+--------+
1 row in set (0.00 sec)

Mark

P.S. I might be slow in responding the next one and a half week when I am on the road.

groenm’s picture

Hi all,

Got it working with tokens. I actually used tokens the wrong way. I only replaced "field_caseno_type" in "$node['field_caseno_type'][0]['value']" with "field_caseno_type-raw" instead of replacing the whole string "$node['field_caseno_type'][0]['value']" with "[field_caseno_type-raw]". I myself hadn't used token before.

It is still unclear (at least to me) why the select list was not working, while the ordinary text fields did. I applied Mooffie's patch and tried to do it by using $node, but could not get it to work. Probably, due to my lack of knowledge on the inner workings of Drupal.

As far as my production site is concerned, it looks like my problem is solved. Now, I have to learn a bit more on the workings of $node and $form_value so I can solve my problems myself in the future.

Rick24 and Mooffie: thanks for your help.

Mark

mooffie’s picture

Status: Active » Fixed

replaced "field_caseno_type" [...] with "field_caseno_type-raw"

Oh. There's a help text there that shows you the correct syntax.

It is still unclear (at least to me) why the select list was not working,

That's because you accessed the form data (the HTML form) as if it were the node. But in case of a selectbox, the HTML form doesn't reflect exactly the data as it's organized in the node. That's why it's inelegant to access the form.

looks like my problem is solved.

OK, so I'll close this issue :-)

Anonymous’s picture

Status: Fixed » Closed (fixed)

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