Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Running a php function every X seconds

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Bloodmorphed
Smarty Rookie


Joined: 20 Aug 2017
Posts: 8

PostPosted: Mon Sep 04, 2017 7:07 am    Post subject: Running a php function every X seconds Reply with quote

I'm wanting to run a php function right as a button is pushed, and then 10 seconds indefinitely until the page is either left, or the action is stopped.

Code:

  <form method="post" action="index.php?mod=Battle">
    <select name="selection">
      {foreach from=$mobs item=mob}
        <option value="{$mob->id}">{$mob->name} ({$mob->id})</option>
      {/foreach}
    </select>
    <input name="battle_mob" type="submit" value="Fight" class="button" />
  </form>


This is where I'd like it to be. I've been trying to figure out a way to do, and I will probably do through jQuery. But as I've not done timing normally, let alone through smarty I thought I'd ask here rather then somewhere else.

Also I;d like for a timer to be shown as well.[/code]
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Sep 04, 2017 7:57 am    Post subject: Reply with quote

The web-browser-based solution would be strictly client-side javascript - probably a javascript timer making an AJAX request to a PHP script.

Smarty has long ago left the building.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Sep 04, 2017 8:42 am    Post subject: Reply with quote

bsmither wrote:
Smarty has long ago left the building.

To clarify: Smarty is a PHP program, PHP is a SERVER scripting language, when you see a page in your browser, process that made it is long since finished working and no longer care about it.
And as said, if you want to have anything happening on the page AFTER the browser have loaded it, you want CLIENT scripting. I.e. JavaScript.
Back to top
View user's profile Send private message
Bloodmorphed
Smarty Rookie


Joined: 20 Aug 2017
Posts: 8

PostPosted: Mon Sep 04, 2017 6:49 pm    Post subject: Reply with quote

I know I have to use JavaScript, the problem is I'm not sure HOW to do it. I've been looking through W3Schools and the such to see what I could do. But the problem isn;t just timing it to run every 10 seconds.

I want the process to run instantly when the button is pressed, and then 10 seconds indefinitely afterward.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Sep 04, 2017 8:06 pm    Post subject: Reply with quote

There is an excellent forum at forums.phpfreaks.com that can help with the PHP necessary to answer the AJAX request and also the javascript necessary to do what you want.
Back to top
View user's profile Send private message
Bloodmorphed
Smarty Rookie


Joined: 20 Aug 2017
Posts: 8

PostPosted: Mon Sep 04, 2017 8:10 pm    Post subject: Reply with quote

Hm. Okay thanks!
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Sep 05, 2017 1:43 pm    Post subject: Reply with quote

In either way, this is not a Smarty question.
Closed.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP