Agreement Expiration Date [RESOLVED]

Hi GF Support Team.

I need help implementing an expiration date of a contract based on the date the agreement is signed.

I tweaked this code based on this post but it returned an invalid code.

Our goal is to have the expiration date auto-populated 6 months after the signed date (today’s date) and the output is ex: “21st of June 2022”.

add_filter( 'gform_field_value', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name,  ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration = date_i18n( 'jS \of F', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days'  => $three,
		'182_days'  => $expiration,
	);
	return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}

Any help would be greatly appreciated.

Thank you!

Liza

Hi Liza. What is the invalid code that was returned? Was the date wrong, or in the wrong format, or did you have an error message?

Looking quickly at the code, there are at least a couple of problems with the code:

add_filter( 'gform_field_value', 'all_the_dates', 10, 3 );

In the first line, gform_field_value should be something like gform_field_value_parametername where parametername is the name you gave to the field in your form which is set up to be populated dynamically. It could be:

expiration
sixmonths
date
mojo

Whatever you use in the field parameter name is the same word you need to use in this filter:

add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );
add_filter( 'gform_field_value_sixmonths', 'all_the_dates', 10, 3 );
add_filter( 'gform_field_value_date', 'all_the_dates', 10, 3 );
add_filter( 'gform_field_value_mojo', 'all_the_dates', 10, 3 );

In this line:

function all_the_dates( $value, $field, $name,  ) {

The comma after $name does not need to be there. I’m not sure if that is causing a problem or not.

If you share the actual error message you are receiving after updating the code, that will help us figure it out. Thank you.

Hi Chris.

Thank you for your reply! To answer your first question, it just say invalid code and the site went down :slight_smile:
OK let me apply your corrections and will get back to you whatever the outcome is.

Thanks Chris!
Cheers,
Liza

1 Like

Hi Liza. That means there is a fatal error which will be logged somewhere, normally the web server error log. WordPress also sends an email to the website administrator. We’ll need the actual error message from one of those two locations to help troubleshoot. Thank you.

Hi Chris.

I added this code:

add_filter( 'gform_field_value_expiration’, 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name  ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration = date_i18n( 'jS \of F', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days'  => $three,
		'182_days'  => $expiration,
	);
	return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}

This is the error:
2022-02-15T01:52:34+00:00 CRITICAL syntax error, unexpected ‘all_the_dates’ (T_STRING), expecting ‘)’ in /var/www/vhosts/lifeskills4kids.com.au/staging.lifeskills4kids.com.au/wp-content/themes/impressense-web-studios/functions.php on line 305

Thanks,
Liza

Possibly a different error than you had the first time. The single quote at the end of gform_field_value_expiration is different than the one preceding and the two wrapping all_the_dates.

1 Like

Fixing that fancy quote to make it a single quote got rid of the error for me.

Aha, yes, I think that was causes the invalid code. Fixed that already. Didn’t return an error but it did not turn out the expected outcome.

add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );

The expiration date is still not auto-populated.

Code in the functions.php

add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name  ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration = date_i18n( 'jS \of F', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'three_days'  => $three,
		'182_days'  => $expiration,
	);
	return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}

I’m not sure what needs to be added/changed to get this result (ex): 22/07/2022

Thank you all!

$expiration = date('jS \of F Y', strtotime($local_timestamp. ' + 6 months'));
$standard = date('d/m/Y', strtotime($local_timestamp. ' + 6 months'));

Results:
15th of August 2022
15/08/2022

Looking at the tree and missed the forest :grinning:

add_filter( 'gform_field_value_expiration', 'all_the_dates', 10, 3 );
function all_the_dates( $value, $field, $name ) {
	// "21st of June" is the format we want
	$local_timestamp = GFCommon::get_local_timestamp( time() );
	$expiration_timestamp = ( 86400 * 182 ) + $local_timestamp;
	$today = date_i18n( 'jS \of F', $local_timestamp, true );
	$expiration_short = date_i18n( 'd/m/Y', $expiration_timestamp, true );
	$expiration_long = date_i18n( 'jS \of F Y', $expiration_timestamp, true );
	$values = array(
		'todays_date' => $today,
		'expiration'  => $expiration_long,
	);
	return isset( $values[ $name ] ) ? $values[ $name ] : $value;
}

The expiration_long variable returns: 16th of August 2022.
The expiration_short variable returns: 16/08/2022.

Update ‘expiration’ => to whichever one you want displayed.

Don’t forget to set the field for dynamic population and use ‘expiration’ as the parameter.

YAY, it worked! I used the short date. Thank you @tugmariner :slight_smile: :blush:

Thanks also @chrishajer :slight_smile:

Cheers guys!

Liza

1 Like