Jump to content

Disable button at set date / time


WAMFT1

Recommended Posts

Is there a way that you can disable a button at a set date and time?

 

For example, my work has a competition site running and I want to give people the option to change their weekly selections by clicking on an edit button up to 6pm on a certain Friday. After this time it either disappears or is just made inactive.

 

ie:

 

Comp 1 -> 'Edit' then disable after 6:00pm 2nd Jan

Comp 2 -> 'Edit' then disable after 6:00pm 9th Jan

Comp 3 -> 'Edit' then disable after 6:00pm 16th Jan etc....

 

I am not even sure where to start with this one.

Link to comment
https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/
Share on other sites

<?
if (time() > strtotime("12/31/2014 6:00PM"))
{ <input name="Disabled" type="button" disabled="disabled" value="Disabled" />; }else{
<input name="Enabled" type="button" value="Enabled" />;}
?>

I have figured out part of this but don't know what to do to get the button to display. Any ideas?

<?
if (time() > strtotime("01/02/2015 5:00PM"))
{ echo'<input name="Disabled" type="button" disabled="disabled" value="Disabled" />'; }else{
echo'<input name="Enabled" type="button" value="Enabled" onclick="location.href='../edit.php'"/>';}
?>

Thanks Barand, Works great, I have tried to link the button to another page but it doesn't work. What am I missing? any suggestions?

The string that you are echoing finishes at the ' after location.href=

 

You need to escape the single quotes within the string

echo'<input name="Enabled" type="button" value="Enabled" onclick="location.href=\'../edit.php\'"/>';

Thanks Barand, worked a treat.

 

Thanks ginerjm, displaying the disabled button is an OCD thing of mine in that it there is symmetry in the look of the page. In the instance of this site the rechecking won't be much of an issue as the login script expires the page after 30 minutes and the cut off time is a good 2 hours earlier. Even if they were late they are still early if you get what I mean.

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.