Formidable Forms

The Most Advanced WordPress Forms Plugin and Form Builder

  • Features
  • Pricing
  • Blog
  • Support
  • Login
  • Get Formidable Forms

frm_skip_form_action

Last Updated: April 30, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Form Actions → frm_skip_form_action
Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Use this hook to conditionally skip Form Actions.

Usage

add_filter( 'frm_skip_form_action', 'form_action_conditions', 10, 2 );

Parameters

  • $skip_this_action (boolean)
  • $args (array)
    • 'action' (object)
    • 'entry' (int or object)
    • 'form' (object)
    • 'event' (string)

Examples

Skip if one of two fields is empty

Use the code below if you would like to stop a form action when one of two fields is empty. Replace 116 with your action ID. Replace 104 and 105 with your field IDs.

add_filter( 'frm_skip_form_action', 'form_action_conditions', 10, 2 );
function form_action_conditions( $skip_this_action, $args ) {
    if ( $args['action']->ID == 115 ) {//replace 115 with your action ID
        if ( is_object( $args['entry'] ) ) {
          $entry = $args['entry'];
        } else {
          $entry = FrmEntry::getOne( $args['entry'], true );
        }

        $field1 = 104;// Replace 104 with your field ID
        $field2 = 105;// Replace 105 with another field ID
        
        $val1 = isset( $entry->metas[ $field1 ] ) ? $entry->metas[ $field1 ] : '';
        $val2 = isset( $entry->metas[ $field2 ] ) ? $entry->metas[ $field2 ] : '';

        if ( $val1 == '' || $val2 == '') {
            $skip_this_action = true;
        }
    }
    return $skip_this_action;
}

Skip if the submitter is Admin

Stop the update email notifications, but only if a non-admin submits the form.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!
add_filter( 'frm_skip_form_action', 'stop_admin_update_email', 10, 2 );
function stop_admin_update_email( $skip_this_action, $args ) {
  if ( $args['action']->ID == 115 ) { //replace 115 with your action ID
    if ( current_user_can( 'administrator' ) ) {
      $skip_this_action = true;
    }
  }
  return $skip_this_action;
}

Only allow the action once

There may be times when an email or another form action is set to trigger on update or after successful payment, but you really only want it to trigger once. This example uses two hooks: one to set when an action has been triggered, and one to stop it the next time.

add_filter( 'frm_skip_form_action', 'stop_multiple_actions', 20, 2 );
function stop_multiple_actions( $skip_this_action, $args ) {
  if ( $args['action']->ID == 115 && ! $skip_this_action ) { //replace 115 with your action ID
    $entry_id =  $args['entry'];
    if ( is_object( $args['entry'] ) ) {
        $entry_id = $args['entry']->id;
    }
    $option_key =  'frm_triggered_' . $args['action']->ID . '_' . $entry_id;
    $was_triggered = get_option( $option_key );
    if ( $was_triggered ) {
        $skip_this_action = true;
    }
  }
  return $skip_this_action;
}

add_action( 'frm_trigger_email_action', 'frm_set_action_triggered', 30, 2 ); // 'email' will need to be replaced with the key for the action
function frm_set_action_triggered( $action, $entry ) {
  if ( $action->ID == 115 ) { //replace 115 with your action ID
    $option_key =  'frm_triggered_' . $action->ID . '_' . $entry->id;
    update_option( $option_key, true );
  }
}

The name of the 'frm_trigger_email_action' hook is dynamic, based on what type of action is being triggered.

Skip based on entry creation date

Some actions may trigger more than once. A recurring payment can trigger an action after some time has passed. This example stops the form action if the entry was not created on the same day.

add_filter( 'frm_skip_form_action', 'stop_multiple_actions', 20, 2 );
function stop_multiple_actions( $skip_this_action, $args ) {
  if ( $args['action']->ID == 115 && ! $skip_this_action ) { //replace 115 with your action ID
        if ( is_object( $args['entry'] ) ) {
          $entry = $args['entry'];
        } else {
          $entry = FrmEntry::getOne( $args['entry'] );
        }

        if ( strtotime($entry->created_at) < strtotime('-24 hours')  ) {
            $skip_this_action = true;
        }
  }
  return $skip_this_action;
}
  • Usage
  • Parameters
  • Examples
    • Skip if one of two fields is empty
    • Skip if the submitter is Admin
    • Only allow the action once
    • Skip based on entry creation date
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms
Install Formidable Lite

Using WordPress and want to get Formidable Forms for free?

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact

Top Features

  • Front End Editor
  • Repeating Fields
  • Views from Entries
  • Calculator Forms
  • Conditional Logic
  • Visual Form Styler
  • Form Templates
  • User Submitted Posts
  • File Upload Forms
  • Spam Protection
  • Multi Page Forms
  • Surveys & Polls
  • Form Graphs & Charts
  • Save and Continue
  • Mobile Forms
  • Stripe Forms
  • PayPal Forms
  • WooCommerce Forms
  • MailChimp Forms
  • User Registration
  • Signature Forms
  • Bootstrap Forms
  • Quiz Maker
  • Zapier Forms
  • Salesforce Forms
  • HubSpot Forms
  • API Webhooks
  • Multilingual Forms
  • Directories

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • Blog

Copyright © 2021 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started