Closed (fixed)
Project:
Validation API
Version:
6.x-1.0-rc4
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Nov 2008 at 19:03 UTC
Updated:
16 Dec 2008 at 20:52 UTC
Hi,
great work so far. Thank you for contributing!
I try to set up a PHP rule like this:
if ( $form_state['values']['field_AnotherFieldOnSameForm'] == 'SomeVal') {
return ($value != 'ValThisField');
}
It should give an error if the field AnotherFieldOnSameForm contains SomeVal AND the field i want to validate contains ValThisField
Is this possible and how? My example gives an error every time.
Merci
Comments
Comment #1
TapocoL commentedFirst of all, if you included the <?php tags in your rule, take them out.
Secondly, you should always return something because the return value is tested to be true (or a value that can be represented as true in PHP). If it is not, then it will throw an error. So, right now if field_AnotherFieldOnSameForm != 'SomeVal', it will fail. I am just assuming that you want it to pass if that field does not equal SomeVal. If you do want it to fail, then there is not technically a problem with the rule you setup.
Here is an example validator rule that will only check the related field to equal 'jkl;' if a field called 'subject' is equal to 'asdf'. If 'subject' is not equal to 'asdf', there are no problems.
Name: multi_field
Type: PHP
Rule:
Message: If subject is 'asdf', then comment cannot be 'jkl;'.
I set it up on a comment form. So, the field values should be the following:
Form ID: comment_form
Field Name: comment
Validator: multi_field
Allow Empty?: (checking doesn't matter because the comment field is always required)
Message: Message: If subject is 'asdf', then comment cannot be 'jkl;'.
Hope this helps.