予約フォームの日付欄と指名キャストのプルダウンで、「Undefined value was submitted through this field.」というエラーが出る。

Contact Form7の最新バージョン(Ver5.9)にアップデートすると、予約フォームの日付欄と指名キャストのプルダウンで、「Undefined value was submitted through this field.」というエラーが出るようになります。

これを回避するには、functions.phpに以下のコードを追記してください。

// カスタムバリデーションルールの追加
add_action( 'wpcf7_init', 'custom_change_select_validation_rule', 99 );
function custom_change_select_validation_rule() {
remove_action( 'wpcf7_swv_create_schema', 'wpcf7_swv_add_select_enum_rules', 20, 2 );
add_action( 'wpcf7_swv_create_schema', function( $schema, $contact_form ) {
$valid_values = range(0, 24); // 例として0時から24時までを有効値とします
$schema->add_rule(
wpcf7_swv_create_rule( 'enum', array(
'field' => 'select_reserve_hour', // 対象のフィールドID
'accept' => $valid_values,
'error' => $contact_form->filter_message(
__( 'Undefined value was submitted through this field.', 'your-text-domain' )
),
) )
);
}, 30, 2 );
}