I am working on a module for which I want the title to be generated by the contect of others fields (for example, Name + Surname).
With Drupal 4.7, I can hide the title, or change the way it is asked in the form. But can I make it an hidden element, automatically generated from the content of other fields ??

Thanks for your help !!

Comments

FixB’s picture

Reading again my question, I don't know if it is clear enough.
With Drupal 4.7, the developper has to define the 'title' field in his module's form, as defined here : http://drupal.org/node/22218#node-titles
What I would like to do for my module is not asking the user to fill a 'title' field, but generate the node's title by combining two other fields in the form.
If anyone know how to code such a thing, I would really welcome his help :p
Thanks again !

FixB’s picture

Please, if you think it is simply not feasible, can someone let me know (so that I don't keep bumping against a wall with no hope :p)

respinos’s picture

Warning: hastily pasted code follows!

Your module can use the form_alter hook to hide the title:

function bogus_form_alter($form_id, &$form) {
  # only alter these form types; a true solution would get this variable from a 
  # stored setting.
  $applicable_types = array("template_task", "template_todo");
  if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id && in_array($form['type']['#value'], $applicable_types)) {
    $form['title'] = array(
      '#type' => 'value',
      '#required' => TRUE,
      '#value' => $form['#node']->title ? $form['#node']->title : '...'
    );
  }
}

and then in the submit case in the nodeapi, you can set $node->title based on any of the attributes in $node.

FixB’s picture

Thank you very much for your answer.
I'm trying to integrate you example in my code, but at the moment, I can't get it to work properly. It seems that if I edit a node, then I can access the good values and generate my title. But on the creation of the node, I can't access the proper field values.
But I'll keep trying :p Thanks again !!

FixB’s picture

Thanks for your help.
I found another solution : I don't put anything in the node->title and change the view of my node : same effect and much more simpler :p