Select field “undefined value” due to “wpcf7_swv_create_schema” action
-
Hi there,
In Version 5.9 CF7 added an enum validation added to dropdown menu fields and checkboxes – so dynamicly created values are invalid data for safety reasons.
As a result the select(and probably also checkboxes) prefilled with taxonomy terms won’t get submitted.
I checked https://stackoverflow.com/questions/78101215/contact-form-undefined-value-was-submitted-through-this-field and simply removing the new action does quickly reenable the form submitting but leaves securitiy issues.
remove_action( 'wpcf7_swv_create_schema', 'wpcf7_swv_add_select_enum_rules', 20, 2 );
in the stackoverflow topic answer https://stackoverflow.com/a/78136065/1165121 is a more detailed way to add the dynamicly created values to the valid values so that part could be secured.
add_action( 'wpcf7_init', 'wpwoodo_change_select_validation_rule', 99 ); function wpwoodo_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 = [ 'value1', 'value2', 'value3' ]; $schema->add_rule( wpcf7_swv_create_rule( 'enum', array( 'field' => 'my_select_field_id', 'accept' => $valid_values, 'error' => $contact_form->filter_message( __( 'Undefined value was submitted through this field.', 'my-text-domain' ) ), ) ) ); }, 30, 2 ); }
maybe thats a feature request here…
After the CF7 Update it looked like that – so something hat to be done:
kind regards
tom
- You must be logged in to reply to this topic.