Forums

Current Date in Field

LikeStuff 22 Jun, 2016
How do I get a field to show the current date? I searched the forum but didn't find an answer.

Thank you!
GreyHead 23 Jun, 2016
HI LIkestuff,

Add a Custom Code action in the form On Load event with code like this
<?php
$form->data['today'] = date('d-m-Y');
?>


And add an input in the Designer tab with the name today and readonly=readonly in the Extra Params box.

Bob
LikeStuff 23 Jun, 2016
Sorry I think I missed something😟

I am using a text box named "current-date".

I add the code below in a Custom Code action on the form On Load event.


<?php
   $form->data['current-date'] = date('d-m-Y');
?>


The date is not showing. What did I miss please?
GreyHead 23 Jun, 2016
Hi LikeStuff,

Is the Custom Code action before the HTML (Render Form) action? In not, please move it up, otherwise this looks OK.

Bob
LikeStuff 24 Jun, 2016
Oh I see. Thank you so much🙂
GreyHead 25 Jun, 2016
Hi Likestuff,

Most of the time ChronoForms runs the actions in the order they are shown in the events. So the HTML (render form) action renders the form HTML, including the values, with the info available at that point.

Bob
javerleo 19 Jun, 2017
Hello.

I'm using chronoforms 6 and it seems custom code is not working. I put the code before "display section", but fields are not filled. Is there some change in the new version? Please see attached image.
Max_admin 20 Jun, 2017
Hi javerlo,

In v6 you should use $this->data instead of $form->data, and the way to do it actually is to use this shortcode in the "value" field instead of using custom code:
{date:Y-m-d}


Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
javerleo 20 Jun, 2017
Thank you, admin.

I will try
This topic is locked and no more replies can be posted.