Hello everyone,

I am trying to create a validation of data that is submitted during the creation of a node. I have a CCK type I call "daily youtube". I dont want users to be able to add the same videos, so in the CCK field I created a field called field_youtube_url which is sort of the unique identifier for each video. When a user tries to create the content but it already exists I want there to be a simple message with a link to the already created node. I tried using the code below to create a module, but it doesnt seem to work, I got this code from here http://drupal.org/node/89599 and tried to modify it.

<?php
function dupe_video_nodeapi(&$node, $op) {

	 if ( $op == 'validate' ) {
		// We only care about nodes of type 'desired type'
		$type = 'content_daily_youtube';  // Change this to the type you want to restrict titles on
		if ( $node->type == $type ) {
			$sql = "SELECT m.field_youtube_url_value, n.nid FROM {node} n JOIN {node_content_daily_youtube} m USING(nid) WHERE type = '%s' AND field_youtube_url_value = '%s'";
			$results = db_query($sql, $type, $node->field_youtube_url);
			$existing = db_fetch_object($results);
			 // We get here on both inserts and updates
			 // For updates we want to make sure the title does not match another one
			 // So we make sure it is an insert ( ! $node->nid )
			 // or for update that we have not just found the node being updated ( $exisiting->nid != $node->nid )
			if ( ( ! $node->nid ||  $existing->nid != $node->nid ) && $existing->field_youtube_url == $node->field_youtube_url ) {
			    $link = l(t('existing %type', array('%type' => $type)), "node/$existing->nid");
			    form_set_error('title', t('There is already a %type called %title, see %link.', array('%type' => $type, '%title' => $node->title, '%link' => $link)));
			 }
		}
	}
}

Any help would he much much appreciated.

Thanks!