Reputation: 99
I have contact form on my website and I allow visitors to decide how many bikes they want to rent (dropdown from 1-20) then to specify how many males (from 0-20) and how many female's (from 0-20) they want to rent. I am getting: "Undefined value was submitted through this field." When someone choose 0 either for men's or female's bikes. So Contact form forces you to choose 1. Then it works. Anyone know how to fix this?
Tried to ask ChatGPT but my forme structure seems ok. So, no reason there.
Upvotes: 8
Views: 8023
Reputation: 2497
If the issue appears with a checkbox, adding free_text
solves the problem since it allows adding values that were not there during at rendering (for example renaming the options using javascript)
[checkbox TN_extraOptions free_text "Option 1" "Option 2" "Option 3" "Option 4" "Option 5" "Option 6"]
Upvotes: 0
Reputation: 79
We have also had this issue on a form using a postcode look up (from Contact Form 7 Conditional Fields).
Our temporary solution is to remove the dropdown address results when the submit button is clicked and hide the notice (that we also added the class .postcode-wrapper
onto. Not a perfect solution but it appears to work in our case and hopefully will for some others.
// Temporary Fix for contact form 7 update validation error on register with us form address lookup
jQuery('.register-with-us-form .wpcf7-submit').on('click', function() {
jQuery('.register-with-us-form .mcpostcode-addressreg').remove();
jQuery('.register-with-us-form .postcode-wrapper').hide();
})
Upvotes: 0
Reputation: 46
Since I often fill my dropdown fields dynamically using the wpcf7_form_tag filter, I have to adapt the new validation rules accordingly. To do this, I first remove the action hook (as already mentioned by @kamilm14) and add a new one, which I can then use to register my own customized validation rule like this:
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 ); }
Upvotes: 1
Reputation: 129
To complete @kamilm14 answer:
You can remove the enum validation for checkboxes like this:
remove_action( 'wpcf7_swv_create_schema', 'wpcf7_swv_add_checkbox_enum_rules', 20, 2 );
Upvotes: 8
Reputation: 323
It looks like this problem is associated with the enum validation added to dropdown menu fields and checkboxes in CF 7 version 5.9 in this commit and this one for checkboxes.
The easiest option for now is probably removing the enum validation for dropdowns like:
remove_action( 'wpcf7_swv_create_schema', 'wpcf7_swv_add_select_enum_rules', 20, 2 );
A more refined approach would involve creating a similar validation rule that incorporates appropriate values. This might be relevant if you're configuring dropdown values based on custom posts, ACF fields, or any other sources.
Upvotes: 26
Reputation: 41
I have the same problem with a select that is dynamically populated via jquery. It has always worked but now gives this error "Undefined value was submitted through this field." when selecting one of the values entered via jquery
I tried a downgrade to Contact Form 7 version 5.8.7 and it works again I suspect that the new version considers the jquery script that adds the various options to the select tag to be something external or potentially malicious; but I have found nothing about it
Upvotes: 4