In the Schema-Woven Validation terminology, a composite rule is a rule that has a set of child rules. Contact Form 7 5.9 and later support composite rule types, all
and any
, with which you can implement conditional logic in user input validation.
Category Archives: Developer’s cookbook
Form status
Each contact form instance rendered on the frontend has a status. The status must be one of the predefined statuses or a user-defined custom status that starts with the custom-
prefix, and transitions from one to another according to user interaction.
Disabling only specific error types of config validator
While you can disable the functionality of the configuration validator, you may feel that disabling the entire functionality is overkill. Another technique that I am describing in this recipe allows you to apply more precise control over the configuration validator. You can disable only the error types you specify.
Continue reading Disabling only specific error types of config validatorCustomizing Brevo’s contact creation
Contact Form 7 has an integration module with Brevo (formerly Sendinblue) that manages a contact database derived from contact form submissions. To add a contact data to the database, Contact Form 7 sends a request to the Brevo API. This recipe describes how you can customize the request parameters using the wpcf7_sendinblue_contact_parameters
filter hook.
Setting upper limit of checkbox selection
In this recipe, I’ll show you how to implement a user input validation that sets the upper limit of checkbox selection. This validation is based on the Schema-Woven Validation (SWV) mechanism, so it has some big advantages over the previous filter-based validation, such as:
- You can use validation rules already defined by SWV, so you don’t need to code the validation logic yourself.
- Once you create an SWV validation rule, the rule can work anywhere as long as SWV is supported. On the other hand, filter-based validation only works on the server side.
Form-tag features
Do you remember when we learned how to register a custom form-tag type in a previous recipe? We used the wpcf7_add_form_tag()
function and set the third parameter to array( 'name-attr' => true )
.
We call it features of a form-tag. Contact Form 7 has a set of predefined features (listed below), and, by specifying some of them through a form-tag type declaration, you can characterize each form-tag instance of the type.
Continue reading Form-tag featuresCustomizing Stripe payment parameters
Stripe‘s payment parameters, such as the currency or the amount of money, are decided by the [stripe]
form-tag placed in the form template. You might want to customize the parameters by changing them dynamically based on the user’s selection or some sort of calculation.
You can do it by using the wpcf7_stripe_payment_intent_parameters
filter hook like in the following coding example:
Accessing user input data
To access user input posted through a contact form, you can refer to PHP’s native global variable $_POST
. Besides this, Contact Form 7’s WPCF7_Submission
class provides a different data source ($posted_data
) that can be used to access user input. What are the differences between $_POST
and $posted_data
? And which one should you use for your purpose?
Custom spam filtering
Spam protection is mission-critical for web forms. The Contact Form 7 plugin provides several types of spam protection modules to effectively block submission by spammers.
Just like other parts of Contact Form 7, its spam-filtering feature is designed to be highly customizable. In this recipe, I’ll show you how to implement a custom spam filter with simple coding examples.
Continue reading Custom spam filteringSharing reCAPTCHA API keys and tokens
With Contact Form 7’s reCAPTCHA (v3) integration ability, you can protect your contact forms from spambots. Since a spambot targets everything—not only contact forms—you may also want to protect other components on your website (such as comment forms) using reCAPTCHA technology.
Fortunately, Contact Form 7’s reCAPTCHA integration is designed to be open and accessible to other components. In this recipe, I’ll tell you how you can retrieve reCAPTCHA API keys and tokens from Contact Form 7 and reuse the data within your own reCAPTCHA plugin.
Continue reading Sharing reCAPTCHA API keys and tokens