I am attempting to set the "title" value of a content type before it becomes "required" . So what happens is the title field becomes hidden based on user name, after filling in the "first name" and "last name" fields I need to take those values and then apply them to the "title" field, before drupal states that the field is required. Here's what I have so far

*  Implements hook_form_alter().

function editorhide_form_alter(&$form, &$form_state, $form_id){
//form id = artist_node_form
//title id = edit-title label: edit-title   

global $user;
global $fullTitle;

if($form_id == 'artist_node_form'){     
   if( $user->name == 'Editor'){        

        // drupal_add_js("jQuery(document).ready(function(){
        //  jQuery('#edit-title').hide();
        // });","inline");              
        $form['#submit'][] = "editorhide_form_submit_handler";



//submit form handler.

function editorhide_form_submit_handler ($form, &$form_state) {

  $fullTitle = array();
  $fullTitle['0'] = $form_state['values']['field_firstname']['und']['0']['value'];
  $fullTitle['0'] .= ' '. $form_state['values']['field_lastname']['und']['0']['value'];
  form_set_value( $form_state['title'], $fullTitle['0'],$form_state);


With the current code it throws a error:: Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, null given, called in


1 Answer 1


First You should write the these kind logic in validate function rather than the submit function.

So instead of

$form['#submit'][] = "editorhide_form_submit_handler";

you should have

$form['#validate'][] = "editorhide_form_submit_handler";

Second the first parameter passed to the function form_set_value is the form element and not the form state value so the function should look like.

form_set_value( $form['title'], $fullTitle['0'],$form_state);

I think what you are trying to achieve can be done with a custom module.

Automatic Nodetitles

"auto_nodetitle" is a small and efficient module that allows hiding of the content title field in the form. To prevent empty content title fields one can configure it to generate the title by a given pattern.

When the token module is installed it's possible to use various node data for the auto generated title - e.g. use the text of a CCK field (since 5.x).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.