This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Zmove
Zmove

Hello,

I'm writing a plugin that have some settings. I could create the Settings model, defined some fields, works well.

One of my field is a button that should trigger a function when I click on it. I thought I could put a data-request="onReset" on my button, and to put this code on my settings model :

public function onReset() {
    trace_log('test');
}

the problem is that, when I click on my button, it display an error popup : "Ajax handler "onReset()" cannot be found"

What do I miss ? Where should I put my onReset function ? I already used the ajax framework on my theme easily, by putting my function in the code tab of my cms page. Where to put that code when you want to do the same thing on backend setting page ?

Thank you

Alex

Adrien - ACTE Solutions
Adrien - ACTE Solutions

Hello, I know the post is old but it might help others.

I came with the same issue recently. You should add your onReset() function to the controller \System\Controllers\Settings. To do so, you must extend it like below in Plugin.php boot() function:

\System\Controllers\Settings::extend(function($controller) {
  $controller->addDynamicMethod('onReset', function() {
    trace_log('test');
  });
}

See documentation on extending controllers: https://octobercms.com/docs/services/behaviors#constructor-extension

Adrien.

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.