/**
 * Implementation of hook_nodeapi().
 *
 */
function uniquetitle_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {  
    case 'validate':     
      _uniquetitle($node);
    break;
  }
}

function _uniquetitle(&$node) { 
  $sql = "SELECT COUNT(*) FROM {node} WHERE title = '%s'";
  if (db_result(db_query($sql, $node->title))) {
    // prevent form submission
    form_set_error('title', t('This title has already been used.'));	
  } 
} 

Comments

sweetchuck’s picture

Thank you for your code snippet. :-) But I think you does not browse the CVS repository before you create this issue. I would be happy if somebody test this module, and give a feedback. I don't want to create a release without 3th part test.
Thanks again for your interesting.

summit’s picture

Version: » 6.x-1.x-dev

SUbscribing, greetings, Martijn

Anonymous’s picture

It needs some work , currently you can't edit a post without changing the title

drubytue’s picture

This would be very useful if I could apply unique titles only to new nodes. My existing database has duplicate titles, so I am not able to use your module to set a content type to unique titles. Otherwise it is just what I need in conjunction with node-import to manage my content workflow.

Here's the error message. Artist is my content type and Bearfoot etc. are node titles for performers at music festivals.

Title duplications in content type Artist. Cannot setable to unique.

* bearfoot
o Bearfoot
o Bearfoot
o ...
* blue highway
o Blue Highway
o Blue Highway
* ...