中给出的数组我在我的wordpress网站的functions.php中有以下代码。它允许我以重力形式控制公司代码。但我想验证对所有形式的工作,但是当我改变gform_field_validation_5_6
到gform_field_validation
(从一种形式的合作,以各种形式的)我得到这个错误:警告:strtoupper()期望参数1是字符串,在/ var/www/
Warning: strtoupper() expects parameter 1 to be string, array given in /var/www/...
我的代码使用方法:
/**
* Validate the submitted Company Code
*
* @since 2016-07-30
* @author Dave Clements
* @link https://www.randomlists.com/string Random String Generator to create new company codes
* @link https://www.gravityhelp.com/documentation/article/gform_field_validation/ Documentation on gform_field_validation()
* @param array $result The validation result to be filtered.
* @param string|array $value The field value to be validated.
* @param array $form The Form Object.
* @param array $field The Field Object.
* @return array The filtered $result
*/
function validate_company_code($result, $value, $form, $field) {
$valid_company_codes = array(
'6XZTPWF3' => 'Company name',
'6XZTPWF3' => 'Company name',
'7DJEHMM7' => 'Company name',
'6XZTPWF3' => 'Company name',
);
// Allow user entry to include lower-case letters.
$capitalized_value = strtoupper($value);
// Check if the entered code is valid.
if (! array_key_exists($capitalized_value, $valid_company_codes)) {
$result['is_valid'] = false;
$result['message'] = 'That company code appears to be invalid. Please try again.';
}
return $result;
}
add_filter('gform_field_validation', 'validate_company_code', 10, 4);
任何想法是什么导致这个错误。
您的'$ value'是一个数组。 –
strtoupper()只能处理字符串。 $ value是一个数组。 –