I want To Populate A Date Field Automatically With Date But 14days after. In A Date Field Read Only?

Hi

I have put a date field into my gravity forms on my website. I want to populate the date field but with a date 14days after sending the form. How do I do this please? I have the date field and form ID. I am able to put snippet or code in Theme Functions but do not know what code to put in? Really could do with some advice or exact code to put in and where in the Theme Functions.php or any other advice? Thanks And Appreciated in advance. . .

Using the filter gform_field_value_$parameter_name you can hook the following function (or similar) with parameter name date_plus_fourteen:

// dynamically populate relative date
add_action( 'gform_field_value_date_plus_fourteen', function( $value ) {

    return date( 'm/d/Y', strtotime('+14 days') );

} );
2 Likes

Ok How do I do it for a specific form and specific field ID? Do I paste this into Theme Functions PHP?

What i am trying to do is populate the date on a specific field using a specific form and a specific date field ID. To populate date but adding 14days. And so it can not be changed for instance it is purchasing a homecare contract that starts 14days after the date when submitted. So date +14 after form submission. TY.

After having added the code above to your site, you can dynamically populate a field with the +14 day value by clicking the field setting Advanced → Allow field to be populated dynamically and then entering Parameter Name // date_plus_fourteen.

1 Like

Ok and I am in UK so will it be d/m/y?

Thank You for helping. The code I paste into Theme Functions.PHP?

Anywhere in the functions. I presume it will work for UK?

Perfect thats works a treat.

Last Question, how do I set it so it cant be changed by the end user? Want it so it cant be changed. Thanks and appreciated.

I have done the code etc but the date is sent on my form ad mm-dd-yyyy allthough the actual field and form is showing dd-mm-yyyy it is just the sent email to myself and my customer? How do I amend so it populates dd-mm-yyyy? Thanks well in advance?

I would like to try again for advice. Here is a screenshot of the issue. It populates but want to change the date format. When It populates in the UK date format. Using the code below works except it populates the wrong days and months if I change to DD-MM-YY. So I am getting there but not quite there.

Also is there a code or snippet I can use once populated that the date can not be amended by the user signing up for plan I offer?

Really would like to get this resolved. Really happy if anyone can assist. Thanks again though 100% for the help to date as would not have this populated otherwise. I am in UK and have a UK site. Regards. . .

// dynamically populate relative date
add_action( 'gform_field_value_date_plus_fourteen', function( $value ) {

    return date( 'm/d/Y', strtotime('+14 days') );

} );

Any Advice Welcome? ? ? Apologies for keep bringing this up? ? ?

Hey Andrew,

Maybe you could use this free plugin by Gravity Wiz to format your date display? I haven’t tried it myself but it would be great if it could work for you.

Cheers,
Phil

I haven’t tried this myself with the function under discussion, but I use the strtotime function and I know it can be adapted to return different date and time formats. You might want to look at this site: PHP: Date Formats - Manual.

The “m/d/Y” portion of the function tells the function to return a date in the American format of mm/dd/yyyy. Replace it with the format you want, using the appropriate date/time format. I think you might want “d-m-Y”.

Give that a try and let us know if it works.

Looks like you’re almost across the finish line here, Andrew, but if you need to do this again or anything more complicated, use our free Populate Dates snippet. It’ll handling formatting the value to that of the Date field you’re populating. It can even populate/modify dates based on the values of other fields.

3 Likes