how to publishing a form only at a certain period ?

hhaneh 18 Mar, 2009
Hi all,

is there anyway to setup a period for the form to posted up and a period where it will unpublished?

What i wish to do is like open the form for registration from 23-3-2009 Morning 8AM to 24-3-2009 12AM only. Is there anyway i can do it like i can set a period when an article can start publishing and when to unpublished it.
GreyHead 18 Mar, 2009
Hi hhaneh,

Yes it is; I did something like this for a client a year or so ago -I'll see if I can dig out the code.

Bob
GreyHead 18 Mar, 2009
Hi hhaneh,

I think you can do this with a little redirect in your form html
<?php
$open = strtotime( '23-Mar-2009 08:00' );
$close = strtotime( '24-Mar-2009 12:00' );
if ( time() < $open || time() > $close )  {
  global $mainframe;
  $mainframe->redirect('index.php');
}
?>
Not tested and may need de-bugging.

Bob

Ps The application I wrote was much more complex than this, allowing for closure at weekends and on holidays as well as times of the day.
hhaneh 19 Mar, 2009
Hi Bob,

Thanks man, it works. It just add in an error message. Haven't found any error.

<?php
$open = strtotime( '18-Mar-2009 08:00' );
$close = strtotime( '19-Mar-2009 23:00' );
if ( time() < $open || time() > $close )  {
  global $mainframe;
  $mainframe->enqueuemessage("Sorry, the registration period is over.", 'error');
  $mainframe->redirect('index.php');
}
?>
GreyHead 19 Mar, 2009
Hi hhaneh,

I added a closing ?> tag to your code just in case someone copies it.

Next time you can save a little typing by adding the message directly into the redirect
$mainframe->redirect('index.php', "Sorry, the registration period is over.", 'error');


Bob

PS I'm just writing a ChronoForms PlugIn that will do this - and quite a bit more !
This topic is locked and no more replies can be posted.