type == "drupal_sites") { // We only care about nodes of type 'drupal_sites' $type = 'drupal_sites'; // we also don't care about updates so lets ditch it $sql = "SELECT count(*) FROM {node} n WHERE n.type = '%s' AND n.title = '%s'"; // check for duplicate title $title_exists = db_result(db_query($sql, $node->type, $node->title)); // check for duplicate database name $db_name_exists = is_cck_field_value_present("drupal_sites", "db_name", $node->field_db_name[0]['value']); // check for duplicate database name $db_username_exists = is_cck_field_value_present("drupal_sites", "db_username", $node->field_db_username[0]['value']); form_set_error('title', t('Duplicate values')); } } /** * Implementation of hook_menu(). */ function develenv_menu($may_cache) { $items = array(); $items[] = array( 'path' => 'test_cck_field', 'title' => t('Test CCK field'), 'callback' => 'test_cck', 'type' => MENU_CALLBACK, 'weight' => 1, 'access' => user_access('access content'), ); return $items; } function test_cck() { $arg1 = arg(1); $arg2 = arg(2); $arg3 = arg(3); $is_present = is_cck_field_value_present("drupal_sites", "db_username", "testsite1"); $is_present = is_cck_field_value_present("drupal_sites", "db_username", "testsite11"); $is_present = is_cck_field_value_present("drupal_sites", "max_num_user", 11); $is_present = is_cck_field_value_present("drupal_sites", "max_num_user", 22); $is_present = is_cck_field_value_present("drupal_sites", "db_name", "testsite1"); $is_present = is_cck_field_value_present("drupal_sites", "db_name", "testsite11"); $is_present = is_cck_field_value_present("drupal_sites", "max_load", .11); $is_present = is_cck_field_value_present("drupal_sites", "max_load", .12); } /** * * This function checks if a value exsists for a cck field * * @param string $content_type_name machine readable name of the content type * * @param string $field_name machine readable name of field * * @param mixed $field_value value that needs to be checked * * @return boolean true if present, else false * */ function is_cck_field_value_present($content_type_name, $field_name, $field_value) { // first lets get field details $qs =<<type; $inline_value = $row->db_storage; } $where_param_type = ""; switch($field_type) { case "text": $where_param_type = "'%s'"; break; case "number_integer": $where_param_type = "%d"; break; case "number_decimal": $where_param_type = "%f"; break; } if ($inline_value) { $qs =<<