Hi Matt, it’s not too hard to accomplish that. First, add a single-line text field to your form. On the Appearance tab, give it a Custom CSS class name of gf_readonly
and on the Advanced tab, check the box “allow field to be populated automatically” and add the parameter name of ‘date’.
Then add this code to your theme functions.php file:
// update '1' to the ID of your form
add_filter( 'gform_pre_render_1', 'add_readonly_script' );
function add_readonly_script( $form ) {
?>
<script type="text/javascript">
jQuery(document).ready(function(){
/* apply only to a input with a class of gf_readonly */
jQuery("li.gf_readonly input").attr("readonly","readonly");
});
</script>
<?php
return $form;
}
Be sure to update the form ID from 1 to whatever your form ID is, or remove the _1 from the filter if you want to have this code available on any form.
Those two steps will give you a field to hold the data, and make the input appear read only. If you want to style that readonly field, please see the advice here:
Go to the “Styling the Fields” section.
The last part is to populate the field with the date when the form is shown. You already gave the text field the parameter name of ‘date’, so you can use this filter to populate the field with a date:
The actual code for you for the date format DDMMYYYY will look like this:
add_filter( 'gform_field_value_date', 'populate_the_date' );
function populate_the_date( $value ) {
// desired format DDMMYYYY
// ref https://www.php.net/manual/en/function.date.php
$local_timestamp = GFCommon::get_local_timestamp( time() );
return date_i18n( 'dmy', $local_timestamp, true );
}
That code can go into the theme functions.php file right near the gform_pre_render code you added for the readonly script.
If you have any questions, please let us know.