I need to add a Machine Name type of field to Nodes of a certain Content Type. It's the same Machine Name field that Drupal is using when creating Content Types.

Example: If I enter "My Title" in the title field, the Machine Name field will be populated with "my_title" via javascript.

Why do I need it? I am referencing nodes to other nodes and want to generate an URI, based on a node referenced, i.e. example.com/node-referenced/node-content

4 Answers 4


There is a machine_name element type for the Form API, but it appears there is no machine name field type in core or in a contrib module. From there, I see three code-driven solutions:

  • It should be possible to crudely alter your node form to replace a text-field widget with a machine name element,
  • but the proper way would be to define a new Field API widget type based on the machine name Form API element type.
  • You can also not use the Field API for, directly add a machine name element in your node edit form through a form alter hook and handle storing it's value yourself.
  • Awesome, that will get me going in the right direction! Oct 17, 2011 at 17:37
  • Do you know how to implement that in a module? I.e. how to make machine_name as a new field type via module. I can't seem to make it work. Oct 17, 2011 at 22:54
  • Never mind. I found a module! Oct 18, 2011 at 0:23

And here is the machine name field:


Courtesy beejeebus, hunmonk, and C_Logemann working on Drupal.org's own project module.


Just found a module that does that: Safeword

Safeword adds a new Field type to Drupal 7: the "Name/Machine Name" combination. This field type can be useful for storing public-facint text and an internal "short" name, similar to the way that Content Type labels and machine names are used in the Drupal administration UI.

Safeword also uses the new 'Machine Name' FormAPI element in Drupal 7 to automatically suggest a machine name based on the text entered into the human-readable field.

Why bother using it? Using Token, Pathauto, and Auto NodeTitles, Safeword can be used as a replacement for Drupal's standard "Title" field, allowing content editors to create a visitor-friendly title with a customizable URL-safe "short" version that's used to build path aliases. The short URL-friendly machine name can also be used as a Views argument. Finally, it makes your Content Type administration page just a tiny bit cooler.


It sounds like you just need a new field on a certain content type, and want the field to be called machine name.

If that is the case do this:

  1. Goto: [yoursite.com]/admin/structure/types
  2. Click Manage fields for the content type you want to add this field
  3. Fill in the details in the add new field row, and hit save

That should add your field, but you may also want to edit the order it is displayed, and you can do that by dragging it up or down, and hitting save.

If you want to change how it is displayed then you need to look at the Manage Display tab, and you can re-order it and change the way it is displayed as well.

  • No, I need to have a Machine Name field. The field that is automatically populated via javascript from the title. For example, if I enter "Node Title", the Machine Name field will automatically be populated with "node_title". Just like you get when you create a new Content Type. Oct 15, 2011 at 6:44
  • Can you not use pathauto to generate the path, and use that? Oct 15, 2011 at 7:58
  • Pathauto will use the machine-named field, instead of the Title, because Title may get altered. Oct 17, 2011 at 17:36

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.