Unique value in Drupal cck fields



Here a quick snippet to have a unique values check in a Drupal cck field.

In this example, we want a unique URL stored in the field_website_link cck field

 

function vs2_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'validate':
if ($node->type=='website' ){
$pass='';
$sql = "SELECT field_website_link_url, nid FROM {content_type_website} WHERE field_website_link_url = '".$node->field_website_link[0][url]."' $sub_filter limit 1";
$result = db_query($sql);
$line = db_fetch_array($result);
if ( drupal_strlen($line[field_website_link_url])>0 ) {
$pass = l("Go and check the existing Drupal Website", "node/".$line[nid]);
form_set_error ('field_website_link', "URL already exists [$pass]");
}
}
break;
}
}

ยป

Comments

Invia nuovo commento

  • Linee e paragrafi vanno a capo automaticamente.
  • Web page addresses and e-mail addresses turn into links automatically.

Maggiori informazioni sulle opzioni di formattazione.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 18 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.