Using Gravity Forms ‘gform_post_form_activated’ PHP action

The gform_post_form_activated action in Gravity Forms is triggered after an inactive form is marked as active, allowing further actions to be performed.

Usage

add_action('gform_post_form_activated', 'my_function', 10, 2);

Parameters

  • $form_id (int): The ID of the form that is being marked as active.

More information

See Gravity Forms Docs: gform_post_form_activated

This action hook is located in forms_model.php.

Examples

Send an email notification when a form is activated

This example sends an email notification to the admin when a form is activated.

function send_email_on_form_activation($form_id) {
    $to = '[email protected]';
    $subject = 'Form Activated';
    $message = "Form ID {$form_id} has been activated.";

    wp_mail($to, $subject, $message);
}

add_action('gform_post_form_activated', 'send_email_on_form_activation', 10);

Log form activation

This example logs form activation to a custom log file.

function log_form_activation($form_id) {
    $log_file = WP_CONTENT_DIR . '/form_activation.log';
    $current_time = date('Y-m-d H:i:s');
    $log_entry = "{$current_time} - Form ID {$form_id} activated" . PHP_EOL;

    file_put_contents($log_file, $log_entry, FILE_APPEND);
}

add_action('gform_post_form_activated', 'log_form_activation', 10);

Update form metadata

This example updates the form metadata when a form is activated.

function update_form_meta_on_activation($form_id) {
    $activation_time = time();
    gform_update_meta($form_id, 'activation_time', $activation_time);
}

add_action('gform_post_form_activated', 'update_form_meta_on_activation', 10);

Perform an action in a custom plugin

This example triggers a custom action in your plugin when a form is activated.

function my_plugin_form_activation($form_id) {
    // Your custom plugin code to perform an action on form activation
}

add_action('gform_post_form_activated', 'my_plugin_form_activation', 10);

Send data to an external API

This example sends form activation data to an external API.

function send_form_activation_to_api($form_id) {
    $api_url = 'https://example.com/api/form_activation';
    $response = wp_remote_post($api_url, array(
        'body' => array(
            'form_id' => $form_id,
            'timestamp' => time()
        )
    ));
}

add_action('gform_post_form_activated', 'send_form_activation_to_api', 10);