Last updated October 28, 2011. Created by g089h515r806 on October 28, 2011.
Log in to edit this page.
1,click the link "Custom PHP function" to add a validation rule using php.
2,on "Add validation rule" form,Enter following info:
Rule name: test Custom PHP
Column:value
Function name: mymodule_validate_myfield
Custom error message: test Custom PHP error message.
3,add mymodule_validate_myfield to one of your custom module file,such as mymodule.module,here is the example code:
function mymodule_validate_myfield($variables){
//drupal_set_message('123456');
//a flag, TRUE means pass, FALSE means fail.
$flag = TRUE;
//maybe what you need is the current value
$value = $variables['value'];
//you could also access other variables as your need
//$item = $variables['item'];
//$delta = $variables['delta'];
//$items = $variables['items'];
//$rule = $variables['rule'];
//$langcode = $variables['langcode'];
//$entity = $variables['entity'];
//Here add you validate logic,for example
// $flag = mymodule_validate_myfield_through_webservice($value);
if($value == 88){
$flag = FALSE;
}
//return TRUE or FALSE
return $flag;
}In this function, you should return TRUE,or FALSE. you could visit context variable through $variables, such as:
$value = $variables['value'];
It is very simple.