Skip to content

Gravity Forms Changing the Entry Date

Chris Eggleston 1 min read

Problem

We need to add back-dated entries in GF for testing purposes with the entry data we are collecting. I looked for a way to edit the entry date in the GF interface, but it appears it’s not directly editable.

Although you can edit Gravity Forms entries, it is not possible to change the entry date from within the entry editor.

While I am not sure why you would need to do this outside of some testing, as this specific user mentioned, I decided to see if I could find a simple solution and found two.

Solution

Fortunately, I was able to come up with two solutions: a code and a no-code solution.

1. No Code: GravityEdit Add-On

This solution does require purchasing an add-on from GravityKit called GravityEdit.

Once this plugin is installed, you can enable it within the form settings. Then you can change the different field values for your entries from within the Entry list page.

2. Code: A Custom WordPress Plugin

This is a custom plugin I created that will add a new meta box to the entry details page so that you can change the entry date.

To use this code, you can either copy the code and add it to a code snippet plugin like WPCodeBox or install it like a normal WordPress plugin.

You can download the zip file here if you choose to install the plugin.

gr-change-entry-date-metabox.phpGist by chriseggGitHub
<?php
/**
 * Plugin Name: Gravity Forms Change Entry Date
 * Plugin URI: https://gravityranger.com/gravity-forms-changing-the-entry-date
 * Description: Adds a meta box to Gravity Forms entry details page allowing admins to change the entry date.
 * Version: 1.0
 * Author: Chris Eggleston
 * Author URI: https://gravityranger.com
 * License: GPL-2.0+
 */

if (!defined('ABSPATH')) {
    exit; // Prevent direct access
}

// Add Meta Box to Entry Details Page
add_filter('gform_entry_detail_meta_boxes', function ($meta_boxes, $entry) {
    $meta_boxes['update_entry_date'] = [
        'title'    => 'Change Entry Date',
        'callback' => 'gf_render_entry_date_meta_box',
        'context'  => 'normal',
    ];
    return $meta_boxes;
}, 10, 2);

function gf_render_entry_date_meta_box($args) {
    $entry_id = rgget('lid'); // Get entry ID from URL

    if (!$entry_id) {
        echo '<div class="notice notice-error"><p>Invalid entry ID.</p></div>';
        return;
    }

    $entry = GFAPI::get_entry($entry_id); // Fetch entry

    if (is_wp_error($entry) || empty($entry) || !isset($entry['date_created'])) {
        echo '<div class="notice notice-error"><p>Invalid entry data.</p></div>';
        return;
    }

    $current_date = $entry['date_created'];
    $current_date_only = date('Y-m-d', strtotime($current_date));
    $current_time_only = date('H:i:s', strtotime($current_date));

    ?>
    <div style="padding: 10px;">
        <?php if (isset($_GET['update_success']) && $_GET['update_success'] == '1') : ?>
            <div class="notice notice-success">
                <p>Entry date updated successfully.</p>
            </div>
        <?php endif; ?>
        <form method="post" style="margin-top: 20px;">
            <p><strong>Current Date:</strong> <?php echo esc_html($current_date); ?></p>
            <p>
                <label for="new_entry_date"><strong>New Date (YYYY-MM-DD):</strong></label>
                <input type="text" id="new_entry_date" name="new_entry_date" value="<?php echo esc_attr($current_date_only); ?>" style="width: 100%; max-width: 300px;">
            </p>
            <?php wp_nonce_field('update_entry_date', 'update_entry_date_nonce'); ?>
            <p>
                <input type="submit" name="update_entry_date_submit" class="button button-primary" value="Update Date">
            </p>
        </form>
    </div>
    <?php

    // Handle Form Submission
    if (isset($_POST['update_entry_date_submit'])) {
        gf_handle_entry_date_update($entry_id, $current_time_only);
    }
}

function gf_handle_entry_date_update($entry_id, $current_time_only) {
    // Verify Nonce
    if (!isset($_POST['update_entry_date_nonce']) || !wp_verify_nonce($_POST['update_entry_date_nonce'], 'update_entry_date')) {
        echo '<div class="notice notice-error"><p>Security check failed.</p></div>';
        return;
    }

    $new_date_only = sanitize_text_field($_POST['new_entry_date']);

    // Validate New Date Format
    if (DateTime::createFromFormat('Y-m-d', $new_date_only) === false) {
        echo '<div class="notice notice-error"><p>Invalid date format. Use YYYY-MM-DD.</p></div>';
        return;
    }

    // Combine New Date with Original Time
    $new_date = $new_date_only . ' ' . $current_time_only;

    // Update Entry Date
    $result = GFAPI::update_entry_property($entry_id, 'date_created', $new_date);

    if (is_wp_error($result)) {
        echo '<div class="notice notice-error"><p>Error updating entry date: ' . esc_html($result->get_error_message()) . '</p></div>';
    } else {
        // Redirect to avoid form resubmission
        $redirect_url = add_query_arg(['update_success' => '1'], remove_query_arg(['update_success']));
        wp_safe_redirect($redirect_url);
        exit;
    }
}

Need More Help?

If you still need help, use the chat or leave a comment below and we’ll get back to you.

Comments

Ask a question or leave a comment

Your email is never shown. For help with a specific form, share what you expected and what happened instead.