Hi all,
I have a page on the website which has an include command (which points to an html form). I want one html form to display during the week, and then at 5pm on a friday afternoon I want to display the same page but have the include command point to another html form. Then on Monday morning at 9am go back to displying the other form. For example:
<?
// display this include during the week
include ‘includes/weekday-form.php’
// display this include during the weekend
include ‘includes/weekend-form.php’
?>
Try this framework which tests for three week day parameters.
The first condition is a switch which allows hard-coding $day and $hour instead of actual date(…)
if any test is true then include the ‘weekday-form.php’
I have left test $t2 and $t3 for you to do
<?php
// either 1 or 0 for test and actual day and time
if(0)
{
$day = date("D"); // actual day
$hour = date("H"); // actual hour
}else{
$day = "Wed";
$hour = "16";
}
echo $day ,' : ', $hour;
// three week day tests, at least one must be true
$t1 = $t2 = $t3 = false;
// $t1 = test for Tue, Wed or Thu
$t1 = in_array($day, array('Tue', 'Wed', 'Thu') );
if($t1)
{
echo '<br >Must be ' .$day;
}
// $t2 = test for Monday after 09:00
// $t3 = test for Friday before 17:00
$inc = 'includes/weekend-form.php' ; // set default to weekend
if ($t1 || $t2 || $t3)
{
echo '<br /><br />Must be during the week';
$inc = 'includes/weekday-form.php';
}
// include $inc;
?>
Ive almost got it working. Its now working correctly apart from I can get it to detect ‘Monday before 9am’. (It detects if its the weekend or if its after 5pm on friday fine). Heres the code:
<?php
// either 1 or 0 for test and actual day and time
if(0)
{
$day = date("D"); // actual day
$hour = date("H"); // actual hour
}else{
$day = "Mon";
$hour = "01";
}
echo $day ,' : ', $hour;
// three week day tests, at least one must be true
$t1 = $t2 = $t3 = false;
// $t1 = test for Tue, Wed or Thu
$t1 = in_array($day, array('Tue', 'Wed', 'Thu') );
if($t1)
{
echo '<br >Must be ' .$day;
}
// $t2 = test for Monday after 09:00
if($day == "Mon" && $hour > 09){
$t2 = true;
echo "<p>After 9am Mon! Display weekday form</p>";
}
// $t3 = test for Friday before 17:00
if($day == "Fri" && $hour < 17){
$t3 = true;
echo "<p>Before 5pm Fri! Display weekday form</p>";
}
$inc = 'includes/weekend-form.php' ; // set default to weekend
if ($t1 || $t2 || $t3)
{
echo 'Must be during the week';
$inc = 'includes/weekday-form.php';
}else{
echo '<br />Must be the weekend!<br /><br />';
}
// include $inc;
?>