Use an AJAX request handler on a backend settings form
8
A backend settings form usually only has a form model, but no separate controller available. If you want to register a custom AJAX request handler you have to add it to the \System\Controllers\Settings
controller. October re-uses this controller for all backend settings pages.
You can use the extend()
method to add a custom handler:
// Plugin.php
public function boot()
{
\System\Controllers\Settings::extend(function($controller) {
$controller->addDynamicMethod('onMyCustomHandler', function() {
return 'handler called!';
});
});
}
You can now call this handler from any custom partial in your backend settings form:
<button class="btn btn-default"
data-handler="onMyCustomHandler">
Trigger AJAX request
</button>
There are no comments yet
Be the first one to comment