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?

Bojangles
  • 99,427
  • 50
  • 170
  • 208
  • 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 '11 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 -> http://plugins.jquery.com/project/timers might help – Al-Punk Nov 21 '11 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 '11 at 14:47
  • Refer this examples: http://stackoverflow.com/questions/2133166/loop-timer-in-javascript http://stackoverflow.com/questions/914951/show-and-hide-divs-at-a-specific-time-interval-using-jquery – Siva Charan Nov 21 '11 at 15:01

2 Answers2

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);

Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
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);

Martin Borthiry
  • 5,256
  • 10
  • 42
  • 59