frm_skip_form_action

Back to Top
Knowledge Base → frm_skip_form_action

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

Formidable Hook - Helpful

Only allow the action once

Submitted by srwells — 7 years ago

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.

Formidable Hook - Helpful

Skip based on entry creation date

Submitted by srwells — 7 years ago

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;
}
Formidable Hook - Helpful

Skip if one of two fields is empty

Submitted by  — 8 years ago

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;
}
Formidable Hook - Helpful

Skip if the submitter is Admin

Submitted by  — 8 years ago

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

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;
}
If you would like to add your own example, click here.

Have something to add?

Click here to provide feedback on this page.