1. Home
  2. Docs
  3. FAQ
  4. How to initialize the conditional logic after an Ajax call?

How to initialize the conditional logic after an Ajax call?

As this is a pretty advanced topic, I will assume that you are familiar with Ajax and WP development. If you are not, please study up, or hire a developer and point them to this page.

Since version 1.5 of the Conditional Fields plugin, it’s possible to load the conditional logic after loading a form trough JavaScript. The most obvious way being trough an Ajax call.

After loading the HTML form, the necessary events need to be registered on the form. This is done by calling 2 functions:

  • wpcf7.initForm($form), which will register the Contact Form 7 events.
  • wpcf7cf.initForm($form), which will register the Conditional Fields for Contact Form 7 events.

note: $form should be replaced by a selector pointing to the actual form, typically jQuery('.wpcf7-form').eq(0).

The following example should get you on your way: https://conditional-fields-cf7.bdwm.be/ajax-example/

Was this article helpful to you? Yes 1 No 1