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
- Install the Conditional Logic Add-on: This is a premium extension available for Ninja Forms.
- 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").
- 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").
- 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_submissionhook 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
-
Survey after checkouthttps://wordpress.org/support/topic/survey-after-checkout/
-
Password protected formshttps://wordpress.org/support/topic/password-protected-forms/
-
Privacy policy checkboxhttps://wordpress.org/support/topic/privacy-policy-checkbox/
-
Adding Share Buttons to Email Confirmationhttps://wordpress.org/support/topic/adding-share-buttons-to-email-confirmation/
-
Add Javascript file via PHP to a specific formhttps://wordpress.org/support/topic/add-javascript-file-via-php-to-a-specific-form/
-
Other languagehttps://wordpress.org/support/topic/other-language-9/
-
Dropdown Valueshttps://wordpress.org/support/topic/dropdown-values-3/
-
WooCommerce Table Edithttps://wordpress.org/support/topic/woocommerce-table-edit/
-
furniture volume calculatorhttps://wordpress.org/support/topic/furniture-volume-calculator/
-
Allow user to add / remove input fieldshttps://wordpress.org/support/topic/allow-user-to-add-remove-input-fields/
-
Coupon code fieldhttps://wordpress.org/support/topic/coupon-code-field-2/
-
How to break a section with some descriptionhttps://wordpress.org/support/topic/how-to-break-a-section-with-some-description/
-
Regarding Pricing Fieldshttps://wordpress.org/support/topic/regarding-pricing-fields/
-
Is it possible to have html editor for textarea field ?https://wordpress.org/support/topic/is-it-possible-to-have-html-editor-for-textarea-field/
-
How to use Developer WP Hook Hook Taghttps://wordpress.org/support/topic/how-to-use-developer-wp-hook-hook-tag/
-
Social fieldhttps://wordpress.org/support/topic/social-field/
-
Enable / Disable Actions if field is filledhttps://wordpress.org/support/topic/enable-disable-actions-if-field-is-filled/