0

I created a content type called "video" and I created a module named df_video.module with:

function df_video_video_node_form_alter(&$form, &$form_state) {
    $form['actions']['submit']['#value'] = t('Upload');
}

I am trying to change the button text of my Video content type form from "Save" to "Upload" but nothing seems to work when I hit refresh. I also tried clearing the cache. I've tried many variations of the function name with no success. I would prefer to use the specific name of the form in the function name so I don't need to do a switch statement.

Also, just out of curiosity does anyone know if there is something special for placing hooks in a .inc.php file? Not doing this currently but I'm thinking it would just be an include to the main module file.

2
  • Are you using Drupal 6 or 7? It can be achieved differently depending on your Drupal version.
    – Aiias
    Commented Mar 16, 2013 at 21:38
  • Drupal 7. Sorry for not including that.
    – Adam
    Commented Mar 16, 2013 at 21:43

1 Answer 1

2

You cannot target only the video_node_form with an existing hook in D7, but you can target all node forms and then check against the node type to alter the form. Take a look at the documentation and comments on hook_form_FORM_ID_alter(). It may also help to check out how the Book module implemented this hook in D7.

function df_video_form_node_form_alter(&$form, &$form_state, $form_id) {
  $node = $form['#node'];
  if ($node->type == 'video') {
    $form['actions']['submit']['#value'] = t('Upload');
  }
}

With regard to your second question, you generally want to place your hooks in the .module file so that they are guaranteed to be picked up by Drupal. There are some cases where this is not necessarily necessary, like in hook_views_api() where you can points to a file containing other views-specific hooks.

2
  • You may need to clear your cache again. If you inspect element of the page and search for the form_build_id, that should be different if it has reloaded the form.
    – Aiias
    Commented Mar 16, 2013 at 22:40
  • I could have sworn I cleared the cache but after a little of time, it started to work. Thank you!
    – Adam
    Commented Mar 18, 2013 at 15:50

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.