Reputation: 2005
I want to disable submit button for a user after clicking one time in a day and re-enable this button on next day.
<input type="submit" class="myButton" id="option" value="submit"/>
What i require is, when i click a submit button the form submits and disables the button for that day. Then it renables for that user only on the next day.
Upvotes: 0
Views: 3635
Reputation: 1
<form name="from" id="myForm"></form>
$('#myForm').bind('submit', function(){
$.ajax({
type:'POST',
cache:false,
url:'/phpFiles/Form.php', //your path file
data:$('#myForm').serializeArray(),
success:function(data){
var msg = $('.dearUserMsg');
msg.slideDown(100, function(){
msg.html(data);});// esse e a resposta do segundo form
}
});
return false;
});
$('#myForm').bind('submit', function(){ // essa e a submit perfeito
$.ajax({
type:'POST',
cache:false,
url:'secondForm.php',
data:$('#myForm').serializeArray(),
success:function(data){
$.fancybox({
content: data,
width: '90%',
height: '50%',
scrolling: 'no',
overlayColor: '#060',
overlayOpacity: .3,
transitionIn: 'elastic',
transitionOut: 'elastic',
easingIn: 'easeInSine',
easingOut: 'easeOutSine',
titlePosition: 'outside',
hideOnOverlayClick: false,
hideOnContentClick: false
}); //('#mainTag')
}
});return false;
});
<input type="submit" value="Submit" id="sButton" />
<div class="dearUserMsg" style="display:none"></div>
do not forget to display none to slideDown work
and its the same thing but response will come inside a fancybox
in the both example the submit button works only one time and the button will normal
Upvotes: 0
Reputation: 1708
I guess the simplest way of doing this would be to store the time and date of the click in a database. I'm going to assume your users have some kind of unique identity, which should be stored alongside the time and date of the click.
When you render this particular form for that user check for a database record, compare the date and time with the current date and time, then display the button depending on the outcome of the comparison.
<?php if ($dbRecord < $timeLimit) : ?>
<input type="submit" class="myButton" id="option" value="submit" disabled = "disabled"/>
<?php else : ?>
<input type="submit" class="myButton" id="option" value="submit"/>
<?php endif; ?>
You will also need to have some kind of validation in your PHP script that will make sure the user isn't just spamming your page by hitting enter after submitting the form for the first time.
Upvotes: 0
Reputation: 33993
Well, you should somehow store if the button is clicked and if yes on what date/time. Or only just keep the date and time and if it's empty (only the first time) it hasn't been pressed yet, and else just check if it was more or less than a day ago.
You could store this value in a text file of a database.
When loading the page do something like this pseudo code:
<?
if ($dateLastPressed < $aDayAgo)
{
echo '<input type="submit" class="myButton" id="option" value="submit" disabled = "disabled"/>';
}
else
{
echo '<input type="submit" class="myButton" id="option" value="submit"/>';
}
Upvotes: 1