Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
quicksketchBecause 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
Comment #2
quicksketchComment #3
Prodigy CreditAttribution: Prodigy commentedI 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.
Comment #4
GuillaumeDuveauI 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.
Comment #5
quicksketchThanks 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:
Comment #6
Prodigy CreditAttribution: Prodigy commentedI 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 :)
Comment #7
quicksketchSounds 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 :)
Comment #8
Prodigy CreditAttribution: Prodigy commentedThat would be a great feature, indeed.
As long as it's "friendly of course" :)
Comment #9
GuillaumeDuveauI'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) :
I use a custom gdirectory_url_validate function because I only want
http://
links allowing only domains and subdomains.Comment #10
mrgoltra CreditAttribution: mrgoltra commentedsubscribing.
Comment #11
Prodigy CreditAttribution: Prodigy commentedHas 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 ...
Comment #12
mrgoltra CreditAttribution: mrgoltra commentedI think the drigg module has this feature. I am sure it checks against a database of submitted links.
Comment #13
crea CreditAttribution: crea commented"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.
Comment #14
Prodigy CreditAttribution: Prodigy commentedOr a function like this maybe?
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedThe links API module does this. If the links API could be combined with this module it would be very useful for us all.
Mark
Comment #16
ccmd00d CreditAttribution: ccmd00d commentedCan anyone comment on the best current method to do this in drupal 6 using CCK and a link field?
Comment #17
Prodigy CreditAttribution: Prodigy commentedhttp://drupal.org/project/unique_field
Comment #18
ccmd00d CreditAttribution: ccmd00d commentedThanks...works great. One more question. Do you know if it is possible to check this unique field prior to clicking the submit / save button?
Comment #19
quicksketchNice, thanks Prodigy. ccmd00d, I think further questions about this should be moved to the Unique Field queue.