There are cases where you’d like to silently post data to an external URL after a popup closes, display content fetched from the database or even modify a box option before it’s displayed to the visitor.
With the PHP Scripts feature all the aforementioned scenarios are now possible. Let's see how that works.
EngageBox fires certain types of events during runtime and enables you to execute PHP when these events occurred just like in the Actions section but this time the events are fired on the server-side. With the proper knowledge of PHP, you can do just about anything and customize the behavior of the popup to fit your needs.
The PHP Scripts area consits of the following 4 sections that are triggered on certain events.
The PHP script added in this area is executed after the box passes the Publishing Assignments check and before the box's layout is rendered. This is rather useful when you want to modify a box option conditionally. For instance, you could modify the box trigger depending on the visitor’s device type or change the background color based on the current time.
The PHP script added in this area is executed after the box's layout is rendered. This is rather useful if you want to modify, append or replace certain parts in the HTML layout. For instance, you could use this event to replace a placeholder variable included in the box HTML with data fetched from a database table.
The PHP script added in this area is executed every time the box opens. You could use this event to connect to a database or trigger a workflow in a 3rd party app.
The PHP script added in this area is executed every time the box is closed. This is rather useful when you want to populate a row in the database and let the respective app know that a visitor has closed a popup.
Frequently Asked Questions
Can I include PHP files within my code?
The PHP Scripts sections allows you to include any external file from within your joomla installation as long as you have the correct path. This is quite useful if you need to use the same PHP code on multiple boxes, you can place the code in a php file and include it in your box's PHP Scripts section.
include JPATH_SITE . '/path/to/file.php'; // Your code here