From reading the code I noticed this neat feature:

If you put [arg1,arg2,...] in the #rules element of the form, the arguments will be passed in an array to the validation function!

This is wonderful and really should be documented! a little README.txt for the poor little module would go a long way!

An example where this was a life-saver: I have to check that no duplicate emails are entered into a "buyers" content type. This worked 100% when adding the now, but failed big time when editing a node. In the validation function you don't know which node you're working with. Validation rule arguments to the rescue!

in a _form_alter for a node add form I have:

$nid = @$form['nid']['#value'];

$form['field_contact_email'][LANGUAGE_NONE][0]['email']['#rules'] =
array("unique_buyer_email[$nid]");

So if we're editing a node, it won't complain that its own address is already in the database, but if we're adding a node with the same email already listed as a buyer, it will complain.

Comments

pedrofaria’s picture

Assigned: Unassigned » pedrofaria
Status: Active » Fixed

Thank you for your warn! I really appreciated it.. and sorry for this biiiig delay.

I had documented this feature at project page.

Thanks,

Pedro Faria

Status: Fixed » Closed (fixed)

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