Home > Mobile >  How can I add a button on settings.php page in moodle?
How can I add a button on settings.php page in moodle?

Time:03-04

So I have an activity module and I want to add a button on the settings.php page which when clicked runs a particular function in locallib.php, I have gone over the adminlib.php to see my options but couldn't find anything that I could make use of aside from using a checkbox that resets itself every time after it is saved but I don't know if that is a good idea nor if I can actually do it.

I've tried this:

    $link = "<a href=".$_SERVER['SERVER_NAME']."/moodle/mod/game/clear.php" . " class='btn btn-danger'>Empty all results</a>";
    $settings->add(new admin_setting_heading('modemptydb', get_string('modemptydb', 'game'), $link));

The button goes to http://localhost/moodle/admin/localhost/moodle/mod/game/clear.php instead of http://localhost/moodle/mod/game/clear.php

CodePudding user response:

I would suggest that you use an admin_setting_heading() object and, within it, create a link (which can be styled as a button, using the Bootstrap classes "btn btn-secondary") that links to a page that will call your function and then redirect back to the settings page.

I've often done something similar, e.g. if the admin has entered some login details for an external server, then I may have a link to test the connection works OK.

You may need to put a warning on the page that the user will need to make sure they save any changes, before they click the button.

  • Related