Using Gravity Forms ‘gform_forms_post_import’ PHP action

The gform_forms_post_import Gravity Forms action allows you to perform actions after importing forms.

Usage

add_action('gform_forms_post_import', 'your_function_name');

Parameters

  • $forms (array) – An array of form objects.

More information

See Gravity Forms Docs: gform_forms_post_import

This hook was added in Gravity Forms 1.9.13.29. The action hook is located in GFExport::import_json() in export.php.

Examples

Display a message after importing forms

Display a message after importing forms.

add_action('gform_forms_post_import', 'my_action_gform_forms_post_import');
function my_action_gform_forms_post_import($forms) {
    GFCommon::add_message('Forms imported successfully.');
}

Send an email after importing forms

Send an email notification to the admin after forms are imported.

add_action('gform_forms_post_import', 'send_email_after_import');
function send_email_after_import($forms) {
    $to = '[email protected]';
    $subject = 'Forms Imported';
    $message = 'The forms have been imported successfully.';
    wp_mail($to, $subject, $message);
}

Log imported forms

Log the imported forms in a custom log file.

add_action('gform_forms_post_import', 'log_imported_forms');
function log_imported_forms($forms) {
    $log_message = "Imported forms:\n";
    foreach ($forms as $form) {
        $log_message .= "- {$form['title']} (ID: {$form['id']})\n";
    }
    error_log($log_message, 3, 'imported_forms.log');
}

Add custom post meta after importing forms

Add custom post meta to the form posts after importing forms.

add_action('gform_forms_post_import', 'add_custom_meta_after_import');
function add_custom_meta_after_import($forms) {
    foreach ($forms as $form) {
        add_post_meta($form['id'], 'imported_on', current_time('mysql'));
    }
}

Update form settings after importing forms

Update the form settings to disable AJAX after importing forms.

add_action('gform_forms_post_import', 'update_form_settings_after_import');
function update_form_settings_after_import($forms) {
    foreach ($forms as $form) {
        $form['enableAjax'] = false;
        GFAPI::update_form($form);
    }
}