In the current 5.x version of auto_nodetitle, it is possible to use the value of a field in the form in the php pattern by using the $form_values variables as in the following syntax:

  global $form_values;
  $title = 'This is a new node written by '. $form_values['name'];
  return $title;

Following the changes to 6.x formapi described in, i had expected to have to update this pattern to use the 6.x-dev version as follows:

  global $form_state;
  $title = 'This is a new node written by '. $form_state['values']['name'];
  return $title;

However, this doesn't seem to work - none of the keys of the $form_state variable seem to be available... am i doing something wrong, is this feature not yet supported in the 6.x-dev version of auto_nodetitle, or is this a more fundamental change as a result of the new FAPI?



tanoshimi’s picture

This works, but is it bad practice to access the results of $_POST directly? Doesn't seem a very FAPI-y way of doing things...

  $title = 'This is a new node written by '. $_POST['name'];
  return $title;
eaton’s picture

Where is this code being executed? the form values are no longer stored in a global variable -- instead they're in $form_state['values'] itself, and are passed along during the full validation and submission cycle.

You can change those form_state values in your validate and submit handlers -- would that be sufficient?

tanoshimi’s picture

Thanks for the reply Eaton (p.s. love the Lullabot podcast!)

The code snippets above are what I've been entering in the 'Pattern for the title' field in the 'Automatic Title Generation' section in admin/content/types/page - they're not contained in module code.

It seems that since the $form_state array is only passed along within the various stages of formAPI processing, it can no longer be exploited from outside the submission/validation lifecycle in the way that the old global $form_values could be in the examples above... using the $_POST solution actually works for me - are there any issues with using this approach?