0

I need to compare two field values.

Let's say I have a content type named "Specimen". The content title is the accepted name of that specimen. A second field, named Synonyms, can be filled by users to suggest synonyms for the accepted name.

What I need is a field validation with that kind of test : If the synonym matches any title of that content type, then display a message (That synonym is actually an accepted name already entered in the database) and invalidate the value entered. Else, the synonym is valid and can be entered in the form.

I know Uniqueness which is a great module to compare titles between them but not between a CCK Field and each title (unless I missed something?)

I have tried to configure a test with the module Field validation but did not manage to get a nice result, even with the test "Match against a field". Maybe it was not set properly.

I guess that Rules can be my friend too but for now, I have always created very simple rules. So I would appreciate any help to build this test.

2
  • you can override the submit handler for the form to perform this check with a simple string position check
    – Geoff
    Mar 20 '15 at 4:03
  • Could you be more specific? Thanks.
    – Toki
    Mar 20 '15 at 13:14
0

Finally, I found a solution with the module Field Validation and a PHP Code validation rule associated to my field Synonyms:

$args=array(':type'=>'specimen');
$titles=db_query('SELECT title FROM {node} WHERE type = :type',$args)->fetchCol();
foreach ($titles AS $title){
if ($this->value==$title){$this->set_error();}
}

It works like a charm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.