Skip Navigation

[Resolved] Saving todays date as a hidden field

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.

Our next available supporter will start replying to tickets in about 5.83 hours from now. Thank you for your understanding.

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 2 voices.

Last updated by Minesh 8 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2687147
t.png

Tell us what you are trying to do?
Save todays date as a hidden field

Is there any documentation that you are following?
Yes, I found a toolset support thread that showed how to create a shortcode and then use that shortcode as a hidden field. It did not work for me.

Details:
I have a custom field named "transactiondate" that I need to save as a hidden field (I cannot use the post date for this task as the post date might not always be the current date the post is published).

The custom code (found on a toolset thread) that is creating the shortcode is:

add_shortcode('wpv-post-today', 'today_shortcode');
function today_shortcode() {
return date( 'F j, Y', current_time( 'timestamp' ));
}

and in my CRED form, I have this:

[cred_field field='transactiondate' force_type='field' class='d-none' readonly='true' value='[today_shortcode]']

but it is not saving anything when the form is submitted.

What am I doing wrong?

AND a little calendar picker (and bracket) is displaying... I'm assuming I'm doing something wrong with the shortcode but the little calendar picker should not be displaying becuase it is a hidden field.

#2687156

See it here: hidden link

#2687207

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Considering the that custom field "transactiondate" you created is date type field. Types saved the custom date field value to database as Unix Timestamp.

You can remove the existing field and try to add the following generic hidden field:
=> https://toolset.com/course-lesson/adding-generic-fields-to-forms/

For example:

[cred_generic_field field='wpcf-transactiondate' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[today_shortcode]"
}
[/cred_generic_field]

Add the following shortcode to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_shortcode('today_shortcode', 'func_today_shortcode');
function func_today_shortcode() {
return time();
}

Register the today_shortcode at:
=> Toolset => Settings => Front-end Content => Third-party shortcode arguments

This will automatically save the current date with your custom date field "transactiondate" when you save the form.