WAMFT1 Posted December 31, 2014 Share Posted December 31, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/ Share on other sites More sharing options...
WAMFT1 Posted December 31, 2014 Author Share Posted December 31, 2014 <? 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? Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/#findComment-1501283 Share on other sites More sharing options...
Barand Posted December 31, 2014 Share Posted December 31, 2014 echo Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/#findComment-1501317 Share on other sites More sharing options...
WAMFT1 Posted January 1, 2015 Author Share Posted January 1, 2015 <? 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? Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/#findComment-1501473 Share on other sites More sharing options...
Solution Barand Posted January 1, 2015 Solution Share Posted January 1, 2015 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\'"/>'; 1 Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/#findComment-1501481 Share on other sites More sharing options...
ginerjm Posted January 1, 2015 Share Posted January 1, 2015 Why even bother to display it after the cutoff date/time? Also - you need to re-check your date/time when the form is submitted to be sure that the edit button wasn't just sitting on a client screen when the cutoff time passed. Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/#findComment-1501483 Share on other sites More sharing options...
WAMFT1 Posted January 2, 2015 Author Share Posted January 2, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/293539-disable-button-at-set-date-time/#findComment-1501506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.