Skip Navigation

[Resolved] Automatically populate a date field in edit post form

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 1 voice.

Last updated by davidL-7 1 day, 16 hours ago.

Assisted by: Minesh.

Author
Posts
#2813232
Screenshot 2025-06-19 at 11.22.41 AM.png

Hi,

I have an Edit Post form and when it get submitted, I would like a date field to get updated with the current day/time. I tried to follow the directions in this support post:

https://toolset.com/forums/topic/how-set-the-content-of-a-date-field-in-a-toolset-form-by-jquery-val/

...but am not able to get it to work. Here's what I've got so far:

In the Edit Post form, I have the date field like so:

<div class="form-group ">
<label for="%%FORM_ID%%_director-approved-date">[cred_i18n name='director-approved-date-label']Director Approved Date[/cred_i18n]</label>
[cred_field field='director-approved-date' force_type='field' class='form-control' output='bootstrap']
</div>

(My plan is to visually hide this with CSS, because I don't want the user to manually set the date; instead I want the value for this field to be set when the form is submitted.)

Then, in the JS Editor pane beneath the form, I have this:

jQuery(window).bind("cred_form_ready", function() {
jQuery( 'input[name="wpcf-director-approved-date[display-only]"]' ).val(new Date());
jQuery( 'input[name="wpcf-director-approved-date[datepicker]"]' ).val(Math.floor(Date.now() / 1000));
});

But it's not working; when the form is submitted and the post is updated, the date field is not getting set. Can you take a look and let me know where I'm going wrong (screenshot of my code attached).

Thanks,
David

#2813268

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please check if you see any Javascript/jQuery error with your brwoser's console where you added the form?

Can you please share problem URL where you added the form as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2813622

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've adjusted the code added to your form's custom JS editor as given under:
=> hidden link

jQuery(document).ready(function($) {
  

    var datefield_id = jQuery('input[name="wpcf-director-approved-date[display-only]"]').attr('id');
	jQuery('#'+datefield_id).datepicker().datepicker('setDate', new Date());
  	jQuery( 'input[name="wpcf-director-approved-date[datepicker]"]' ).val(Math.floor(Date.now() / 1000));
});

Can you please confirm it works as expected.

#2813687

That did it Minesh, thank you so much for your support!