Back to Community

How to Conditionally Control Form Actions in Ninja Forms

Content

Many Ninja Forms users need to control when specific form actions, like email notifications or payment gateways, are triggered. A common scenario is having a form with multiple payment options, where you only want the PayPal action to run if the user selects PayPal, and a separate action to run for another method like SEPA.

Why This Happens

By default, all actions added to a Ninja Form will execute upon successful submission. There is no built-in way in the core plugin to conditionally enable or disable these actions based on user input. This can lead to situations where a user selects a bank transfer but is still redirected to PayPal, causing confusion.

The Solution: Using the Conditional Logic Add-on

Based on community discussions, the recommended way to achieve conditional actions is by using the official Conditional Logic add-on from the 'Ninja Forms – The Contact Form Builder That Grows With You' team. This add-on provides the functionality to create "if-then" rules for your form actions.

Step-by-Step Guide

  1. Install the Conditional Logic Add-on: This is a premium extension available for Ninja Forms.
  2. Create Your Form Fields: Add the field that will control the logic, such as a Radio Button or Checkbox List field for payment options (e.g., "PayPal" and "SEPA").
  3. Configure Your Actions: For each action you want to control (e.g., "PayPal Express" and an "Email Action" for SPA orders):
    • Edit the action settings.
    • Look for the Conditional Logic settings (often in an "Advanced" tab).
    • Create a rule that states this action should only run if your specific payment field has the value of its corresponding option (e.g., the "PayPal Express" action only runs if the payment field value is "PayPal").
  4. Test Thoroughly: Submit the form while selecting each different option to ensure the correct actions are triggered.

Important Considerations

  • This solution requires a paid add-on and is not part of the free version of Ninja Forms.
  • The Conditional Logic add-on can control most actions, including emails, redirects, and integrations with payment gateways like PayPal.
  • For more complex workflows, custom code using the ninja_forms_after_submission hook or the WP Hook action may be necessary, but that is an advanced developer-oriented solution.

By implementing conditional logic, you can create sophisticated, user-friendly forms that behave exactly how you need them to based on the choices your visitors make.

Related Support Threads Support