What is the difference between число and количество? As you can see, the “Other” option is missing and there are a couple of fields that are irrelevant to the user in certain cases. If $result-invalidate() is called, that field will fail validation and you will get a form error. This plugin adds conditional logic to Contact Form 7.. Only the questions showing up are required (i.e. Otherwise your code example perfectly solved my problem at hand. Answer everyone by discussing everyone’s problems. I had some trouble getting the correct value from a checkbox “group”. jQuery(‘input[type=tel]’).addClass(‘wpcf7-validates-as-required’); jQuery(‘input[type=tel]’).attr(“aria-required”, “true”); jQuery(‘input[type=tel]’).attr(“placeholder”, “Téléphone*”); } // If the tel field doesn’t have any value, we put back the email field to what it was else if (nom == ‘tel’) { jQuery(‘input[type=email]’).addClass(‘wpcf7-validates-as-required’); jQuery(‘input[type=email]’).attr(“aria-required”, “true”); jQuery(‘input[type=email]’).attr(“placeholder”, “Email*”); }, Meanwhile, thank you for your immense patience. Version Control For Salesforce — Branching Strategy. “n” or “y”). By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Finally, you probably want to show the user the field that is required based on their downdown selection. If you have any questions, let me know. Thanks for contributing an answer to Stack Overflow! What's the word equivalent to, "Announcement! your coworkers to find and share information. trim( wp_unslash( strtr( (string) $_POST[$name], “\n”, ” ” ) ) ) : ”; if ( “phone-number” == $name ) : if ( ” == $value && ” == $_POST[’email’] ) : $result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) ); endif; endif; if ( “email” == $name ) : if ( ” == $value && ” == $_POST[‘phone-number’] ) : $result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) ); endif; endif; return $result; }. Bad performance review despite objective successes and praises.

If $_POST[‘contact-form’] is equal to “Phone,” I want the phone field to be required: I have an extra check for the email. Did something change about the code for current CF7 versions? Congratulations, you are a hero! How do I generate dynamic form from custom field post type in Wordpress?

This is all done in Jquery .. textarea_B is only required if checkbox_A is selected. Then, the function checks the current tag type.

What happens if a motor draws more amps than a battery can provide? Sometimes you may want to have a required field in Contact Form 7 only when another form field has a certain value. When contacting us, please include the following information in the email: User-Agent: Mozilla/5.0 _Windows NT 10.0; Win64; x64_ AppleWebKit/537.36 _KHTML, like Gecko_ Chrome/83.0.4103.116 Safari/537.36, URL: wordpress.stackexchange.com/questions/193205/conditional-required-fields-for-wordpress-contact-form-7. Hope this helps! To subscribe to this RSS feed, copy and paste this URL into your RSS reader. I believe you can just check for blanks in both instead of looking at a contact method.

Did computer games for Commodore 64 really take "25 minutes" to load "if everything went alright"? wpcf7_is_url( $value ) ) { $result->invalidate( $tag, wpcf7_get_message( ‘invalid_url’ ) ); } }, if ( ‘tel’ == $tag->basetype ) { if ( $tag->is_required() && ” == $value && !$_POST[‘contrat’]) { // added a condition !$_POST[‘contrat’] to oly apply if there is not the “contrat” field $result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) ); } elseif ( ” != $value && ! wpcf7_is_tel( $value ) ) { $result->invalidate( $tag, wpcf7_get_message( ‘invalid_tel’ ) ); } }. Attention! If one of them is entered, he should be able to send his request. Contact form 7 submit without completing all required fields. We want to make our plug-in modifications safe from future plug-in updates so we will tie into the same filters that the plug-in uses. assign a condition to contact form checkbox to show optional text in email. Why aren't fixed build platform 3D printers popular?

Without completely understanding what you’re looking to do, I wonder if something like this would work? it worked for me. And I want to be sure they check at least one of those boxes. What I did is add this in functions.php of my theme : // remove the contact form 7 original filters remove_filter( ‘wpcf7_validate_tel’, ‘wpcf7_text_validation_filter’, 10, 2 ); remove_filter( ‘wpcf7_validate_tel*’, ‘wpcf7_text_validation_filter’, 10, 2 ); remove_filter( ‘wpcf7_validate_email’, ‘wpcf7_text_validation_filter’, 10, 2 ); remove_filter( ‘wpcf7_validate_email*’, ‘wpcf7_text_validation_filter’, 10, 2 ); // add my own filters add_filter( ‘wpcf7_validate_tel’, ‘ideead_champ_conditionnel’, 10, 2 ); add_filter( ‘wpcf7_validate_tel*’, ‘ideead_champ_conditionnel’, 10, 2 ); add_filter( ‘wpcf7_validate_email’, ‘ideead_champ_conditionnel’, 10, 2 ); add_filter( ‘wpcf7_validate_email*’, ‘ideead_champ_conditionnel’, 10, 2 ); function ideead_champ_conditionnel($result, $tag) {, if ( ‘text’ == $tag->basetype ) { if ( $tag->is_required() && ” == $value ) { $result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) ); } }, if ( ’email’ == $tag->basetype ) { if ( $tag->is_required() && ” == $value && !$_POST[‘contrat’] ) { /added a condition !$_POST[‘contrat’] to oly apply if there is not the “contrat” field $result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) ); } elseif ( ” != $value && ! So something like this, What is your favorite drink? Make sure Contact Form 7 and Conditional Fields for Contact Form 7 are both installed on your WordPress site. However, for those looking to use it, remember to fix the apostropes etc. I was wondering if you would mind providing me with the Contact Form 7 code you are using and then I can look into updating my code. I was quite happy seeing there is a way to hack into CF7’s validation. ", sed with next line (`+N` option) and frequency (`~N`) together. Thanks again, Chris. for this particular line if ( $tag->is_required() && empty( $value ) ) I need to change it to check: How can the 3rd point be coded? their categories were checked in the first question). rev 2020.10.30.37923, Stack Overflow works best with JavaScript enabled, Where developers & technologists share private knowledge with coworkers, Programming & related technical career opportunities, Recruit tech talent & build your employer brand, Reach developers & technologists worldwide, contact form 7 conditional required checkbox. We’re not, of course, going to modify the plug-in’s files directly. Hope this helps! As long as I don’t have those fields or don’t check the checkbox, the form just won’t validate. Sometimes you may want to have a required field in Contact Form 7 only when another form field has a certain value. Required fields are marked *, Conditional Required Contact Form 7 Fields. This worked great. Asking for help, clarification, or responding to other answers.

The Overflow #45: What we call CI/CD is actually only CI. So, I will need to set my own custom validations for both text and email fields: For both the text (phone) and email fields, I am using the function, my_site_conditional_required, for my own custom validations. or "Attention! Thanks for the comment. add_filter( ‘wpcf7_validate_tel’, ‘xxx_conditional_required’, 9, 2 ); add_filter( ‘wpcf7_validate_tel*’, ‘xxx_conditional_required’, 9, 2 ); function xxx_conditional_required($result, $tag) { $tag = new WPCF7_Shortcode( $tag ); $value = isset( $_POST[$name] ) ? Adds conditional logic to Contact Form 7. Would the rest of the UK lose anything more than honor if Scotland exits the UK? As you may know, HTML has two types of elements for text input fields: for a single-line input; and