How to make a unique content title

I am new to drupal and I want my title to be unique, so is there any module for it or can I autocomplete to view my past name name. please answer in detail

Thanks in advance:)

+6
drupal drupal-6
source share
2 answers

You can use the http://drupal.org/project/unique_field module. It performs additional validation when the node user is created or updated to require the node header or other specified fields to be unique.

+4
source share

Scenario # 1 - Unique Node

hook_node_validate () is what you need if you are working with Drupal 7

Either you can simply use this code below in your custom module, or you can extract the repository from unique_title git that you need to pull into your module directory for your project, and then activate the module.

/** * Implements hook_node_validate(). */ function unique_title_node_validate($node, $form, &$form_state) { if (!isset($node->nid)) { $title = $form_state['values']['title']; $results = db_select('node')->fields('node', array('title'))->condition('title', $title, '=')->execute(); $matches = array(); foreach ($results as $result) { $matches[$result->title] = check_plain($result->title); } if (isset($matches) && !empty($matches)) { form_set_error('title', t('Title must be unique')); } } } 

Scenario # 2 - Autocomplete Node Header

hook_form_alter () and hook_menu () can help you with this to autocomplete Node headers while working with Drupal 7.

Either you can simply use this code below in your user module, or you can extract the repository from autocomplete git that you need to pull into your module directory for your project and then activate the module.

In your user module, use the code below:

 /** * Implementation of hook_form_alter(). */ function module_form_alter(&$form, &$form_state, $form_id) { $form['title']['#autocomplete_path'] = 'unique_node_autocomplete_callback'; } /** * Implements hook_menu(). */ function module_menu() { $items['unique_node_autocomplete_callback'] = array( 'page callback' => 'autocomplete_unique_node_autocomplete_callback', 'file' => 'module.inc', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), ); return $items; } 

In your module.inc file, use the AJAX callback below:

 /** * AJAX Callback */ function module_unique_node_autocomplete_callback($string = "") { $matches = array(); if ($string) { $result = db_select('node') ->fields('node', array('nid', 'title')) ->condition('title', db_like($string) . '%', 'LIKE') ->range(0, 10) ->execute(); foreach ($result as $node) { $matches[$node->title . " [$node->nid]"] = check_plain($node->title); } } drupal_json_output($matches); } 
0
source share

All Articles