0

I would like create an event where users can post some content every 10 minutes.

So, the submit button must be allow during 1 minute for that. Moreover, users can check a countdown during the unallow period.

Is it possible with JavaScript/jQuery or PHP?

4
  • 1
    Clientside verification (JS/jQuery) can be tempered with. I'd use a serverside verification (PHP), but you can use JS/jQuery to toggle the button and show the countdown. Maybe you want to update from time to time via ajax.
    – Smamatti
    Nov 21, 2011 at 14:46
  • This is not possible in PHP since it is a server side language. You should try javascript and since you mentioned Jquery, the Jquery Timers -> plugins.jquery.com/project/timers might help
    – Al-Punk
    Nov 21, 2011 at 14:46
  • @Armand This is not true. Of course you can check the submission in a PHP script (if it is allowed again), deny the operation and show an error.
    – Smamatti
    Nov 21, 2011 at 14:47

2 Answers 2

0

Yeah, when the page loads you can start with the submit button disabled by default in the html markup.

then use a coundown timer, here is a jquery one that I have used before http://keith-wood.name/countdown.html

Click on the callbacks tab in the link provided for code examples, inside your callback/trigger function you will add the following javascript or something similar.

$('#submitButtonId').attr('disabled', 'false);

1
  • forgot to mention that the callback function gets triggered automatically when the time runs out.
    – Robbo_UK
    Nov 21, 2011 at 17:26
0

Try this:

In your php post method set the next time in a session var:

<?php

   //intser post code
   $_SESSION['next_post'] = time() + (10 * 60);

Then in your template print this js:

<script>
var nextPostTime = <?=$_SESSION['next_post']?>;
setInterval(function(){
    if((new Date()).getTime() > nextPostTime ){
       $('#newpostID').show(); // this is the element id of the form 
       setTimeout(function(){
            $('#newpostID').hide();
            nextPostTime = (new Date()).setMinutes((new Date()).getMinutes + 1)
        }
       ,60000);

    }
}, 1000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.