Covid-19: We are open for business as usual and continue to fully support new and existing clients. Contact Us
Top Lines

Run a tools file in Concrete5 via Ajax

by Dave Reeder , 16 July 2018

Dave Reeder
Run a tools file in Concrete5 via Ajax
In Concrete5 we can place php files in the tools directory, which we can run with ajax. This means we can load that php file without refreshing the page on page load, or when we click a link or button etc.

First of all we add our tools file under /application/tools.  For testing we can just add a log entry:

defined('C5_EXECUTE') or die("Access Denied.");

Log::AddEntry('Hello World');

Save this as test_tool.php.

Calling our tools file via ajax:

In the page or file where we want to call the tools file, we need to add the path to the tool at the top:

$tools_url = Loader::helper('concrete/urls')->getToolsURL('test_tool');

Note how you don't add .php to the end of the file and you don't put the whole path - Concrete5 knows what to do with just the above.

Then in our file we can add the ajax like so:

            url: "<?php echo $tools_url ?>", 
            context: document.body            
        }).done(function() {
            console.log('ajax complete');

Note, this will trigger the tools file on page load.

All you then need to do is refresh the page and check the logs and you should see your message from your tools file!

Join the Discussion...

Back to Blog

Get Important News & Offers

Enter your email to receive monthly news and special offers from Made Simple Media:

You can unsubscribe at any time, please read our privacy policy for more information.

Get a FREE Quote...

Contact our friendly team for a FREE no-obligation quote...

Call now on 0800 111 4504

Stay Informed...

Enter your email address to receive occassional emails with special offers, relevant news and useful tips:

Please note, we never share your data with any third party and you can unsubscribe from emails at any time and request that your data is deleted.