0

Gravity Forms offers a hook to modify field values when exporting an entry list using the gform_export_field_value hook. They show an example on how to change the User ID to the User Display Name on Export in their documentation.

I'm looking to change the Date Format for the Entry Date field. Here is what I have so far but doesn't seem to be working:

add_filter( 'gform_export_field_value', 'export_entry_date_value', 10, 4 );
function export_entry_date_value( $value, $form_id, $field_id, $entry ) {

    if( $field_id == 'date_created' ) {
        return !empty( $value ) ? date('F', strtotime($value) ) : $value;
    }

    return $value;
}

Here is information on the hook: gform_export_field_value

Any ideas?

2
  • is the "Entry Date field" in question, a date input field that you created? or is it the actual submission date of the gravity form you're after? Commented Dec 16, 2017 at 5:03
  • The Entry Date data is created by Gravity Forms and is an default Export data field option. The User ID data is processed the same way... that is why I referenced that option in the documentation. It's NOT a created field in the form, it's data captured by Gravity Forms.
    – katart
    Commented Dec 18, 2017 at 13:04

1 Answer 1

2

You can't modify date_created on Export

Gravity Forms date_created field isn't actually a field that's affected by that hook. If you look in /exports.php you'll find in start_export() that they bypass the filter for ID's date_created and payment_date and hard-code force the use of Y-m-d H:i:s

foreach ( $leads as $lead ) {
    GFCommon::log_debug( __METHOD__ . '(): Processing entry #' . $lead['id'] );

    foreach ( $fields as $field_id ) {
        switch ( $field_id ) {
            case 'date_created' :
            case 'payment_date' :
                $value = $lead[ $field_id ];
                if ( $value ) {
                    $lead_gmt_time   = mysql2date( 'G', $value );
                    $lead_local_time = GFCommon::get_local_timestamp( $lead_gmt_time );
                    $value           = date_i18n( 'Y-m-d H:i:s', $lead_local_time, true );
                }
                break;
            default :
                $field = RGFormsModel::get_field( $form, $field_id );

                $value = is_object( $field ) ? $field->get_value_export( $lead, $field_id, false, true ) : rgar( $lead, $field_id );
                $value = apply_filters( 'gform_export_field_value', $value, $form_id, $field_id, $lead );

                ...

Instead

You can create a custom field in your form, make it a hidden field, then use another gform_pre_submission hook to fill it with your server time on submission.

Being a GravityForms customer, their support is superior, maybe they've got better tricks up their sleeves. They're also pretty open to suggestions - opening a ticket as a suggestion to add a hook for that date format there might be worth a try.

4
  • Based on the code provided, do you think I can change the $value by checking if $field_id == 'payment_date'?
    – katart
    Commented Dec 18, 2017 at 19:59
  • not at all. date_created and payment_date and hard-coded exceptions - the break at the end of their case ends their processing within that loop - so there's no chance of them hitting the required filter. Commented Dec 18, 2017 at 20:03
  • Ah. I see that the filter is only within the default case, so that would mean the filter doesn't apply to any other case check.
    – katart
    Commented Dec 18, 2017 at 20:08
  • I'll look into a gform_pre_submission hook. I already created a Hidden field for the User Display Name that uses a dynamically populated parameter.
    – katart
    Commented Dec 18, 2017 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.