For a Drupal 7 site, I'm trying to alter a form into multi-step and want to change the label of a field based on some answer from the first step, which is the reason for my question.

I tried modifying $form[$field_name]['und']['#title'] but the label gets set back to default sometime after the alter function. I tried using an after_build function, but maybe I'm using it wrong because it still doesn't change.

Edit: The answer on Why is hook_form_alter() so messy? explains which label I should change.

  • 3
    Have you tried $form[$field_name]['und'][0]['value']['#title']? – Clive Apr 30 '12 at 20:00
  • Are you using any other plugins, such as Display Suite (which is a module worth looking at as an alternative to hook_form_FORM_ID_alter) – Johnathan Elmore Apr 30 '12 at 20:16
  • 1
    @Clive, I tried that now. That seems to work when altering the node form. It is not working when altering the user_register_form. Weird. I should be more specific in my question about which form, but I was interested in a general answer to learn what the best way to programmatically modify field labels in D7 should be. – Stacey Borsody Apr 30 '12 at 20:32
  • 1
    @StaceyBorsody This might help – Clive Apr 30 '12 at 20:33
  • @Clive Thanks, that does help. You don't by chance know where in the process that 'value' (or 'nid') array gets built and if it can be re-built, do you? – Stacey Borsody Apr 30 '12 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.