Hi guys
Need help. I have a small contact form in my footer, I’ve used the contact form controller template and added it to site.php.
On one of my other pages I have created a controller with the code below. Now when I go to that page, the site.php controller isn’t being loaded, and I keep getting an error. I’ve tried following the guide for a shared controller, which I don’t think I got the code right so that didn’t work. But I also tried adding the contents of the site.php controller to my controller and that doesn’t work either. I get the “Undefined variable $success” error.
Here is my controller for my page. How do I add site controller to it?
<?php
return function($kirby, $pages, $page) {
date_default_timezone_set('Europe/Belgrade');
$thuam = $friam = $fripm = $satam = $satpm = $sunam = '';
$dow = date('D'); // Your "now" parameter is implied
// Time in HHMM
$hm = (int)date("Gi");
switch(strtolower($dow)){
case 'thu': //THURSDAY
if ($hm >= 0 && $hm < 959) {echo "";};
if ($hm >= 1000 && $hm < 1400) {$thuam = "text-success fw-semibold fs-6 blink";};
if ($hm >= 1401 && $hm < 2359) {echo "";};
break;
case 'fri': //FRIDAY
if ($hm >= 0 && $hm < 959) {echo "";};
if ($hm >= 1000 && $hm < 1400) {$friam = "text-success fw-semibold fs-6 blink";};
if ($hm >= 1401 && $hm < 1759) {echo "";};
if ($hm >= 1800 && $hm < 2359) {$fripm = "text-success fw-semibold fs-6 blink";};
break;
case 'sat': //FRIDAY
if ($hm >= 0 && $hm < 959) {echo "";};
if ($hm >= 1000 && $hm < 1400) {$satam = "text-success fw-semibold fs-6 blink"; };
if ($hm >= 1401 && $hm < 1759) {echo "";};
if ($hm >= 1800 && $hm < 2359) {$satpm = "text-success fw-semibold fs-6 blink";};
break;
case 'sun': //FRIDAY
if ($hm >= 0 && $hm < 959) {echo "";};
if ($hm >= 1000 && $hm < 1400) {$sunam = "text-success fw-semibold fs-6 blink";};
if ($hm >= 1401 && $hm < 2359) {echo "";};
break;
}
return [
'thuam' => $thuam,
'friam' => $friam,
'fripm' => $fripm,
'satam' => $satam,
'satpm' => $satpm,
'sunam' => $sunam
];
}
?>
This is for a timetable, and if the time matches, it will apply a css style to the text.