I have a cck node where the users may submit about any web page, submit comments and provide the web link... like a link directory. My need is to avoid duplicate entries. The easiest way for this is to compare links as the user submits the new node.
I would be glad if you may provide some hints how to resolve this need.

Regards

Comments

quicksketch’s picture

Category: feature » support

Because this is a very case-specific task you want to accomplish, it would be better to handle this outside of the link module. Create a new custom module which implements the hook_form_alter function, then add some custom logic that checks the values of all entered links when the $op parameter is on 'validate'.

If you're not familiar with the hook_form_alter function, this guy just so happens to be trying to do something very similar: http://www.whatwoulddrupaldo.org/catching-duplicates-with-hook-form-alter

quicksketch’s picture

Status: Active » Closed (fixed)
Prodigy’s picture

I noticed this was from a long time ago, but this function is still desireable. What would be the best way to get this accomplished now using a custom CCK content type with a link field?

Basically, checking to see if the link inputted is a duplicate.

GuillaumeDuveau’s picture

I want this too, a little differently : I have a custom form where the user just inputs an URL, then I want to check if it's already in the link database (for all the nodes). Going to investigate more... shoudn't be that hard.

quicksketch’s picture

Version: 4.7.x-1.x-dev » 5.x-2.0
Category: support » feature
Status: Closed (fixed) » Active

Thanks for keeping discussion in this issue. If it's a generic enough solution, I'd be glad to accept a patch. The uniqueness checking should probably be limited to that specific content type, but if desired I wouldn't object to having a set of radio buttons:

Uniqueness:

( • ) No unique URL checking
(   ) Unique URL within node type
(   ) Unique URL within field instances
(   ) Unique URL within all link fields
Prodigy’s picture

I definitely think everyone is on the same page. I also agree it should be Content type specific.

I'm sure you have a better idea, but when configuring the link in admin, the user (admin) has an option to not allow duplicate URLS. If a duplicate is submitted, it would either

A.) Error Message (friendly of course)
B.) Redirect to the node containing the URL that is in question of being a duplicate
C.) Your idea is just as good as mine :)

quicksketch’s picture

Sounds like a great idea Prodigy. How about:

C) Error Message (friendly of course), including the title and a link to the node containing the URL that is in question of being a duplicate :)

Prodigy’s picture

That would be a great feature, indeed.

As long as it's "friendly of course" :)

GuillaumeDuveau’s picture

I'm just beginning with Drupal so implementing this properly into the module is above my skills. I'm just posting this in case anyone is interested but it is NOT implemented AT ALL in the link module.

I have a custom gdirectory module, inside I build a form that just lets input one URL, checks if it's not already in the database for the content type website. If no, the form validates and takes the user to the node edit with all the link fields (and others) :

function gdirectory_form_validate($form_id, $form_values) {
  if ( !isset($form_values['url']) ) form_set_error('url', t('You must provide an URL.'));
  elseif (!gdirectory_url_validate($form_values['url'])) form_set_error('url', t($form_values['url']." is not a valid URL or contains files, directories or query parameters. Please try again."));
  else {
    $url = gdirectory_url_clean($form_values['url']);
    $result = db_query("SELECT c.nid FROM {content_type_website} c WHERE c.field_url_homepage_url LIKE '%".$url."%'");
    if (db_num_rows ($result)) {
      while ($val = db_fetch_array($result)) $nid = $val["nid"];
      form_set_error('url', t($url." is already in our database, <a href=\"/node/$nid\">check it out</a>."));
    }
  }
}

I use a custom gdirectory_url_validate function because I only want http:// links allowing only domains and subdomains.

mrgoltra’s picture

subscribing.

Prodigy’s picture

Has anyone been able to get this working? I would implement this right away. Sketch, I'll give you a $25 I-tunes card if you can help out! : ) The logic can be borrowed from the Drigg module ...

mrgoltra’s picture

I think the drigg module has this feature. I am sure it checks against a database of submitted links.

crea’s picture

"Unique field" module has this feature, but it seems to be unsupported and there is no 6.x version. Also using that module I faced another problem: it counts different URL forms as different fields so for example:
"http://site" and "site" are different URLs for "unique_field"
Another example is "http://site" and "http://site/" - even though these are different URLs strictly speaking, in the internet it usually means same url.
With this behaviour uniqueness is myth because users may enter different forms of the same URL, either accidentally or intentionally ( to break site limits, for example ).

In my opinion, this feature should be implemented so all forms of URL should be treated as same URL. Also would be nice to have link to nodes with same URL in the error message.
I guess one can just borrow most of the code from "unique_field" and adapt it to our need.

Prodigy’s picture

Or a function like this maybe?

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);
Anonymous’s picture

The links API module does this. If the links API could be combined with this module it would be very useful for us all.

Mark

ccmd00d’s picture

Can anyone comment on the best current method to do this in drupal 6 using CCK and a link field?

Prodigy’s picture

ccmd00d’s picture

Thanks...works great. One more question. Do you know if it is possible to check this unique field prior to clicking the submit / save button?

quicksketch’s picture

Status: Active » Fixed

Nice, thanks Prodigy. ccmd00d, I think further questions about this should be moved to the Unique Field queue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.