How to capture current time as variable from my imput submit? [SOLVED]

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
caiocald
Registered User
Posts: 60
Joined: Mon Feb 26, 2018 9:32 pm
Location: Brasil
Name: B!
Contact:

How to capture current time as variable from my imput submit? [SOLVED]

Post by caiocald » Sun Jul 21, 2019 11:14 pm

Code: Select all

<form action="{{ path('red1000_pontuacao_formulariopontuacao') }}" method="post" id="modal-details">
<input type="hidden" name="forum_id" value="{{ FORUM_ID }}">
<input type="hidden" name="topic_id" value="{{ TOPIC_ID }}">
<input type="hidden" name="author_user_id" value="{{ TOPIC_POSTER }}">
<input type="hidden" name="post_date" value="{{ CURRENT_TIME }}">
							
I am developing a form that will receive some data and will need to capture the current time the user will click on the form.

i tried {current_time}, but it returns the value of "0" How can I do this?
Last edited by caiocald on Mon Aug 05, 2019 3:36 pm, edited 1 time in total.

User avatar
david63
Registered User
Posts: 16404
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: How to capture current time as variable from my imput submit?

Post by david63 » Sun Jul 21, 2019 11:30 pm

Which time are you trying to use? Server time, board time or user timezone time? How precise does the time have to be?

Normally you would use the time() PHP function in the backend. If you are wanting to capture time on the form then you will probably need to use some js.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
caiocald
Registered User
Posts: 60
Joined: Mon Feb 26, 2018 9:32 pm
Location: Brasil
Name: B!
Contact:

Re: How to capture current time as variable from my imput submit?

Post by caiocald » Sun Jul 21, 2019 11:36 pm

I would use the same configuration that phpbb uses in post_time, I believe it is the "user timezone"

User avatar
caiocald
Registered User
Posts: 60
Joined: Mon Feb 26, 2018 9:32 pm
Location: Brasil
Name: B!
Contact:

Re: How to capture current time as variable from my imput submit?

Post by caiocald » Mon Jul 22, 2019 12:05 am

If someone has an example extension that has a similar function put here please

I'm a beginner in programming and currently I can only develop in phpbb compared to ready examples

User avatar
david63
Registered User
Posts: 16404
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: How to capture current time as variable from my imput submit?

Post by david63 » Mon Jul 22, 2019 7:22 am

caiocald wrote:
Sun Jul 21, 2019 11:36 pm
I would use the same configuration that phpbb uses in post_time
That, effectively, is using PHP time()
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
3Di
Former Team Member
Posts: 14062
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to capture current time as variable from my imput submit?

Post by 3Di » Mon Jul 22, 2019 2:01 pm

Use Twig since you already are using it there.
https://twig.symfony.com/doc/2.x/filters/date.html -> https://www.php.net/manual/en/function.date.php

{{ "now"|date("U") }} returns the seconds since the Unix Epoch, like time() in PHP.

then
<input type="hidden" name="post_date" value="{{ "now"|date("U") }}">
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
EA117
Registered User
Posts: 830
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: How to capture current time as variable from my imput submit?

Post by EA117 » Mon Jul 22, 2019 4:50 pm

3Di wrote:
Mon Jul 22, 2019 2:01 pm
Use Twig since you already are using it there.
Wouldn't this approach expect to capture the current time at the moment the template was rendered to HTML (i.e. during the HTTP GET), rather than the current time "if and when" the user ever eventually submitted the form (as part of an HTTP POST)?

You shouldn't need a form field to track or tell you "when was this form POSTed by the user", because whatever PHP code is being given the opportunity to run in response to the POST can simply ask "what time is it?" (By calling the PHP time() function.)

That is how to get "a time like post_time", which is not describing "when was the HTML document originally generated." The post time describes "when was the submit button finally invoked, if ever."

User avatar
3Di
Former Team Member
Posts: 14062
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to capture current time as variable from my imput submit?

Post by 3Di » Mon Jul 22, 2019 4:54 pm

EA117 wrote:
Mon Jul 22, 2019 4:50 pm
That is how to get "a time like post_time", which is not describing "when was the HTML document originally generated." The post time describes "when was the submit button finally invoked, if ever."
Edit: yes that's it, renders the time when the template was rendered to HTML. I haven't tested it but now.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
david63
Registered User
Posts: 16404
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: How to capture current time as variable from my imput submit?

Post by david63 » Mon Jul 22, 2019 5:44 pm

3Di wrote:
Mon Jul 22, 2019 4:54 pm
it, renders the time when the template was rendered to HTML.
That is not what the OP was asking - he wants to use the same time that post_time uses. Also if there is a need to have multiple use of the that time then using the PHP time() function, if it is make into a variable, will achieve that.

The main issue is that we do not know what the OP is trying to achieve, so everything is supposition.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
3Di
Former Team Member
Posts: 14062
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to capture current time as variable from my imput submit?

Post by 3Di » Mon Jul 22, 2019 5:47 pm

david63 wrote:
Mon Jul 22, 2019 5:44 pm
That is not what the OP was asking
Actually, I know. I posted the code without trying it out.
david63 wrote:
Mon Jul 22, 2019 5:44 pm
The main issue is that we do not know what the OP is trying to achieve, so everything is supposition.
I know what is trying to achieve, and I didn't ask myself any questions tough.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
caiocald
Registered User
Posts: 60
Joined: Mon Feb 26, 2018 9:32 pm
Location: Brasil
Name: B!
Contact:

Re: How to capture current time as variable from my imput submit?

Post by caiocald » Mon Aug 05, 2019 3:35 pm

Hello guys!

Yes, my need was only in the time () function

Code: Select all

$time = time();
After that I used a WHERE in the database query, specifying the time interval based on multiples of 1 day.

Code: Select all

WHERE p.post_time > ' . (time() - (86400 * 7)) . '
Thank you for your help!
Learning how to develop phpbb extension has been an amazing experience!
I didn't imagine that I would get here

Post Reply

Return to “Extension Writers Discussion”