내 function.php에 다음 코드가 있습니다. 그것은 나를 중력의 형태로 회사 코드를 제어 할 수있게 해줍니다. 하지만 유효성 검사가 모든 형태에서 일하고 싶어하지만 난 (모든 형태의 하나 개의 형태에서 작동) gform_field_validation
에 gform_field_validation_5_6
을 변경하면이 오류 얻을 :경고 : strtoupper()는 매개 변수 1을 문자열로, array는/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);
이 오류의 원인은 무엇입니까. 이 기능 위의 코멘트를 읽으면
'$ 값'은 배열입니다. –
strtoupper()는 문자열 만 처리 할 수 있습니다. $ 값은 배열입니다. –