0

How can I copy the value of one field into another during a node edit?

I'm trying to take the value of a text field and have it populate the title field. I'm thinking I can use the Ajax framework and $form_state, but I haven't quite got it yet. Or, is there a way to do this on submission? The Title field is hidden so Ajax isn't required.

In case this helps, the scenario is this: user edits a node, fills in one text field and that value automatically populates the Title field in addition to the current field.

2
  • 1
    If you want to replace the title field only with some other fields content, you could use Automatic Nodetitles module (drupal.org/project/auto_nodetitle).
    – Volker
    Jan 5, 2013 at 14:59
  • Neat! I don't need the whole module, but looking at the code for the module got me just what I needed. Thanks.
    – cdmo
    Jan 5, 2013 at 15:06

1 Answer 1

2

@Volker's tip gave me everything I needed and it's pretty simple as it turns out.

if (!empty($form_state['values']['some_other_field'])){
  $form['title']['#value'] = $form_state['values']['some_other_field'];
}

Set that in a hook_form_FORM_ID_alter and it works great. The part I didn't have was the #value.

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.