I want to alter the form for a content type I created for videos. The type is called Videos. How would I use hook_form_alter to alter the form to create the content?


The form ID is used as the id attribute on the form when it renders.

For content types the pattern is also predictable: node-[TYPE_NAME]-form. So in your case you're looking for: hook_form_node_videos_form_alter().

Another way to handle it is to use the main hook_form_alter() and check the $form_id parameter when you load the form you'd like to target.

  • i get syntax errors using - between node and videos and when i use _ it doesnt seem to be executing. Can i simply add this hook to the video module or do i need my own module just to alter the video form? so my function looks like video_form_node_video_form_alter – BrandenB171 May 6 '16 at 20:56
  • 1
    Sorry I mistyped that - they should always be underscores. Do NOT update the existing module as future updates to that module will overwrite your changes. Create your own module. – acrosman May 6 '16 at 21:03
  • perfect that worked. is that the same form for editing the node? – BrandenB171 May 6 '16 at 21:17
  • 1
    Yes, nodes have just one form used for both create and edit. – acrosman May 6 '16 at 21:19

You can also just look at the generated markup. the form_id is always present as a hidden form_element, so just search for "form_id" in the source code and you should find it. Make sure you're looking at the correct form wrapper, often there are multiple forms (e.g. search/signup/login blocks)


Enable the development module then in your own .module file to get the form_id

function hook_form_alter(&$form, &$form_state, $form_id) { dpm(form_id);//get the form_id dpm(form);//get the form }

Save the file flush the cache and you can see the form_id.


In Drupal 8, navigate to the devel tab on the webform, click on render. Expand the variables and search for 'webform_id'. You can find the webform id here.

Your Answer

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

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