[Solved] Date field to record the date and time when the send button is pressed

Assuming that you use
- PHP form plugin
- set to run onBeforeProcess
- set to "On" = "New"
- 'aa_tickets___data_inoltro_tickets' is a date element

Code:
$right_now = new JDate();
$formModel->updateFormData('aa_tickets___data_inoltro_tickets', $right_now, true);
 
Are you sure that works? I would have thought you'd need to format the date, $right_now->format('Y-m-d H:i:s'), or some such.

-- hugh
 
this where it is:
- set to "On" = "New"

maybe is "Require Once"

anyway:
I get the date (GMT, back 2 hours)
at each subsequent change the date is updated to the current time (it must remain the initial one)

Perhaps we are close to the solution, we need:
  1. record the date and time only on the first save
  2. correct time from GMT to local (all time settings are on local)
 
I solved the question of the hour:
PHP:
$right_now = new JDate('now +2 hour');
Good... if this works for you. Just note that it'll be wrong again at some point in time if your "+2 hours" is true only during daylight saving time.
There's also something regarding timezones on this page: https://docs.joomla.org/How_to_use_JDate

----------------------------------

Now I have to solve only
record the date and time only on the first save

Seen my post here?
Also, in the "date" element plugin, set "Always return today's date" to "No".
(At "Yes", it would obviously always overwrite the date and time with the current one, also on edit. With that set to "No", you'll probably not even need the form plugin.)
Done that?

And again, as mentioned, if this element were set up correctly, you wouldn't even need to bother with the PHP form plugin. Also see this "thread" from just a few days ago: https://fabrikar.com/forums/index.p...te-after-save-form-only-the-first-time.50653/
 
I assume the problem here is that "Default to current date" will use date/time at form load, but he needs the exact saving time
I have a very long form, it takes at least 4 minutes to compile it;
I would like to capture the time when the form is sent and saved in the database (it is also sent by email)
That's why I've proposed the php plugin.
But:
As far as I know the timestamp should do this. Timestamp should show the local server time, so maybe your server is not setup correctly (or not in your local timezone).
http://fabrikar.com/forums/index.php?wiki/timestamp-element/
Same with JDate returning 2 hours off: is your Joomla timezone set correctly?
while not passing a timezone will allow the JDate object to use the default timezone set.
 
Of course I corrected how you indicated to me, these are my settings:
 

Attachments

  • date-time.png
    date-time.png
    29.9 KB · Views: 174
my VPS is set to local time (Rome)
Joomla set to local time (Rome)
all date time fields are set to local time
 
perhaps to fix the date definitively?
PHP:
$timezone = new DateTimeZone( JFactory::getUser()->getParam('timezone') );
$date->setTimezone($timezone);
$formModel->updateFormData('aa_tickets___data_inoltro_tickets', $timezone, true);
 
Fabrik is doing timezone handling itself.
$right_now = date('Y-m-d H:i');
$formModel->updateFormData('test___date_time', $right_now, true);

running with
"on"=new
Process script = onBeforeStore or onBeforeProcess

is doing exactly what you want (store time of saving, only on new records, don't change on edit) on my site.

date element setting local or UTC doesn't matter
Fabrik3.9 or current GitHub doesn't matter, too
 
Last edited:
sorry for my syntax error

however when I re-open the form to update, the date continues to update :(


PHP:
$right_now = date('Y-m-d H:i');
$formModel->updateFormData('aa_tickets___data_inoltro_tickets', $right_now, true);
 
Last edited:
I figured out where I made the mistake, ON was set to "both"

in this field, the Italian localization, there aren't the tooltips suggestion

Many thanks
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top