Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

Add a Form Action

Last Updated: April 28, 2020

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Creating Add-ons → Add a Form Action

A form action is something that is done after an entry is submitted, updated, or deleted. Create a new form action as shown below.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

Relevant hooks

Note: The hooks below are only available post Formidable 2.0.

  • add_action('frm_registered_form_actions', 'add_my_action');
  • add_action('frm_trigger_my_action_name_create_action', 'my_create_action_trigger', 10, 3);
  • add_action('frm_trigger_my_action_name_update_action', 'my_update_action_trigger', 10, 3);
  • add_action('frm_trigger_my_action_name_delete_action', 'my_delete_action_trigger', 10, 3);
  • add_action('frm_trigger_my_action_name_action', 'trigger_my_action', 10, 4);

Register the action

Start by adding the frm_registered_form_actions hook to register your action.

add_action('frm_registered_form_actions', 'register_my_action');
function register_my_action( $actions ) {
    $actions['my_action_name'] = 'MyActionClassName';
   
    include_once( dirname( dirname( __FILE__ ) ) . '/path-to-your-class/MyActionClassName.php');
    
    return $actions;
}

Now in the MyActionClassName.php file, you may add something like this:

<?php

class MyActionClassName extends FrmFormAction {

	function __construct() {
		$action_ops = array(
		    'classes'   => 'dashicons dashicons-format-aside',
		    'limit'     => 99,
		    'active'    => true,
		    'priority'  => 50,
		    'event'  => array( 'create', 'update' ),
		);
		
	    $this->FrmFormAction('my_action_name', __('My Action Name', 'formidable'), $action_ops);
	}

	/**
	* Get the HTML for your action settings
	*/
	function form( $form_action, $args = array() ) {
	    extract($args);
	    $action_control = $this;
?>
	    <table class="form-table frm-no-margin">
	    <tbody>
	    <tr>
		    <th>
			    <label>Template name</label>
		    </th>
		    <td>
		    	<input type="text" class="large-text" value="<?php echo esc_attr($form_action->post_content['template_name']); ?>" name="<?php echo $action_control->get_field_name('template_name') ?>">
		    </td>
	    </tr>
	    <tr>
		    <th>
		    	<label>Content></label>
		    </th>
		    <td>
		    	<textarea class="large-text" rows="5" cols="50" name="<?php echo $action_control->get_field_name('my_content') ?>"><?php echo esc_attr($form_action->post_content['my_content']); ?></textarea>
		    </td>
	    </tr>
	    </tbody>
	    </table>

	    // If you have scripts to include, you can include them here
<?php
	}
	
	/**
	* Add the default values for your options here
	*/
	function get_defaults() {
	    return array(
	        'template_name' => '',
	        'my_content'=> '',
	    );
	}
}

You can replace 'dashicons dashicons-format-aside' with the class you want for the action icon. If you don't want to add your own icon, you can use the dashicons that are already loaded by WordPress.

At this point, you should be able to add your action to a form and save the settings correctly. If the settings are not saving correctly, please double check your code up to this point.

Perform an action

Now, you can do something after an entry is created, updated, or deleted.

On create

This hook is only fired when an entry is created:

add_action('frm_trigger_my_action_name_create_action', 'my_create_action_trigger', 10, 3);
function my_create_action_trigger($action, $entry, $form) {
     // Do some magic
}

Replace the my_action_name text with the name you have given to your action. This name is used in two other places and they must be identical. It is referenced in the first code block:
$actions['my_action_name'] = 'MyActionClassName';
and the second code block:
$this->FrmFormAction('my_action_name', __('My Action Name', 'formidable'), $action_ops);

On update

This hook is only fired when an entry is updated:

add_action('frm_trigger_my_action_name_update_action', 'my_update_action_trigger', 10, 3);
function my_update_action_trigger($action, $entry, $form) {
     // Do some magic
}

Replace the my_action_name text with the name you have given to your action.

On delete

This hook is only fired when an entry is deleted:

add_action('frm_trigger_my_action_name_delete_action', 'my_delete_action_trigger', 10, 3);
function my_delete_action_trigger($action, $entry, $form) {
     // Do some magic
}

Replace the my_action_name text with the name you have given to your action.

On create, update, or delete

This hook is especially useful if you want to do the same thing regardless of whether an entry is created or updated.

add_action('frm_trigger_my_action_name_action', 'trigger_my_action', 10, 4);
function trigger_my_action( $action, $entry, $form, $event ) {
     $settings = $action->post_content;
    // Do your magic here
}

Replace the my_action_name text with the name you have given to your action.

  • Relevant hooks
  • Register the action
  • Perform an action
    • On create
    • On update
    • On delete
    • On create, update, or delete
Categories
×

Categories

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

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

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
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 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 See User Reviews