Jump to content

restricting the form submission time for all users same


mythri

Recommended Posts

I have a form with 6 text boxes to enter numbers. When 3 or more users logs in to this page, it starts counting the seconds. each user enters some numbers to any of the text boxes. The page/form submits on each 30 seconds. When the form submits, i want to get all the data for each text box.


Here the problem is: user opens this URL and if he refreshes the page, from that time it calculates his 30 seconds, but by that time other users have finished his 20 seconds... Now my form does like this which i don't want. Form submission should not be based on user's page refresh and all. Once they join this group, it has to be same for all the users.


I am not getting how to get the server time and keep it the same for all users whoever logs in. Can somebody please help me in this?


Now i am doing like this



<form method="post" name="myForm" id="myForm" action="result.php">
<div class="col-md-1 col-sm-2 col-xs-3">

<input type="text" class="t1 img" name="box1[]" onKeyPress="return numbersOnly(this, event);" onpaste="return false;" />
</div>
<div class="col-md-1 col-sm-2 col-xs-3">
<input type="text" class="t2 img" name="box2[]" onKeyPress="return numbersOnly(this, event);" onpaste="return false;" />
</div>
<div class="col-md-1 col-sm-2 col-xs-3">
<input type="text" class="t3 img" name="box3[]" onKeyPress="return numbersOnly(this, event);" onpaste="return false;" />

</div>
<div class="col-md-1 col-sm-2 col-xs-3">
<input type="text" class="t4 img" name="box4[]" onKeyPress="return numbersOnly(this, event);" onpaste="return false;" />

</div>
<div class="col-md-1 col-sm-2 col-xs-3">
<input type="text" class="t5 img1" name="box5[]" onKeyPress="return numbersOnly(this, event);" onpaste="return false;" />

</div>
<div class="col-md-2 col-sm-2 col-xs-3">

<img src="dice.gif" />
</div>
<div class="col-md-2 col-sm-2 col-xs-3">


</div>
<div class="col-md-1 col-sm-2 col-xs-3">
<input type="text" class="t6 img1" name="box5[]" onKeyPress="return numbersOnly(this, event);" onpaste="return false;" />

</div>
<input type="button" onclick="myFunction()" value="Submit form">

<script type="text/javascript">
setTimeout(function(){ document.getElementById("myForm").submit(); }, 30000);

</script>


How can i set the time for all the users, it should not change even if they refresh, it has to be same for all the users.


Hope i have communicated properly.


Link to comment
Share on other sites

Not sure I understand, but

 

Store a value in the session for when the form needs to submit itself.

a) If there is no value there then generate it as the current time + 29 seconds (first visit)

b) If there is a value there and it is in the future then don't change it (they reloaded too early)

c) If there is a value there and it is in the past then generate it again (second and later visits)

 

- 29 seconds instead of 30 means there is some leeway in the system.

- Only process the form data in case ©, and probably only if the time is within a second or two of the expected submission time.

 

Use that value +1 second (to get back to 30), then compare it to the current time to figure out how many seconds are left for the timer.

 

All that assumes pages render and are delivered to the client within about a second. If you need something even more precise then you'll need something even more complex.

Link to comment
Share on other sites

Probably your best bet is to just choose some fixed schedule and make your script sync the submission time to that. So for example you'd define that the form submits every 30 seconds starting at 00:00:00 (midnight). When someone loads the page, you calculate how long until the next 30-second marker and make that your submission time.

 

So if someone loads the page at say 1:22:13 am, you'd calculate that the form should submit in 17 seconds, making it submit at 1:22:30. If the amount of time between the page loading and the next window is small, you might want to bump them ahead to the following window. For example, if someone loads the page a 1:00:28 rather than give them 2 seconds to submit, give them 32 seconds so their submission counts toward the 1:00:30 - 1:01:00 window.

 

Once you get that bit working, you need to think about how to handle the actual submission. Due to network/processing delays you'll not be able to have everything perfectly in sync no matter how hard you try, so you need to define some sort of acceptable window during which submissions are accepted along with a way of associating submissions with a specific interval period. For example maybe if the submission is received within 2 seconds of the target time accept it, otherwise reject it.

 

A lot of what you need to do here comes down to you deciding what you want to your application to do and what sort of tolerances you're willing to accept. Once you've defined all of that mess coding it to work as defined won't be all that difficult.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.