/**
* 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
Comment #1
sweetchuckThank 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.
Comment #2
summit commentedSUbscribing, greetings, Martijn
Comment #3
Anonymous (not verified) commentedIt needs some work , currently you can't edit a post without changing the title
Comment #4
drubytue commentedThis 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.