Using Gravity Forms ‘gform_post_update_form_meta’ PHP action

The gform_post_update_form_meta action fires after form meta has been updated for any form in Gravity Forms.

Usage

To apply this action to all forms:

add_action('gform_post_update_form_meta', 'your_function_name', 10, 3);

To target a specific form, append the form id to the hook name (format: gform_post_update_form_meta_FORMID):

add_action('gform_post_update_form_meta_1', 'your_function_name', 10, 3);

Parameters

  • $form_meta (Form Object): The current form data.
  • $form_id (int): The form id.
  • $meta_name (string): The name of the meta updated.

More information

See Gravity Forms Docs: gform_post_update_form_meta

This action was added in Gravity Forms version 1.9. The source code is located in GFFormsModel::update_form_meta() in forms_model.php.

Examples

Send an email when form meta is updated

add_action('gform_post_update_form_meta', 'update_data', 10, 3);

function update_data($form_meta, $form_id, $meta_name) {
    GFCommon::send_email('[email protected]', '[email protected]', '', '', 'Form ' . $form_id, 'Form Updated at ' . date('Y-m-d H:i:s'));
}

This example sends an email to a specified address when any form’s meta is updated. The email contains the form ID and the date and time of the update.

Log form updates to a file

add_action('gform_post_update_form_meta', 'log_form_updates', 10, 3);

function log_form_updates($form_meta, $form_id, $meta_name) {
    $log_message = "Form {$form_id} updated: " . date('Y-m-d H:i:s') . "\n";
    file_put_contents('form_updates.log', $log_message, FILE_APPEND);
}

This example logs form updates to a file named form_updates.log, including the form ID and the date and time of the update.

Update a custom post type on form meta update

add_action('gform_post_update_form_meta', 'update_custom_post_type', 10, 3);

function update_custom_post_type($form_meta, $form_id, $meta_name) {
    $args = array(
        'post_type' => 'your_custom_post_type',
        'meta_key' => 'form_id',
        'meta_value' => $form_id,
        'numberposts' => 1
    );

    $custom_posts = get_posts($args);

    if (!empty($custom_posts)) {
        $post_id = $custom_posts[0]->ID;
        update_post_meta($post_id, 'form_last_updated', date('Y-m-d H:i:s'));
    }
}