How do I handle a button being clicked?

How do I handle a button being clicked?

by Sean Thornber -
Number of replies: 1

Hey guys, I'm super new to moodle development so please go easy on me!

I'll start with some context, I have a block that displays a form that contains a 'leaderboard' of students enrolled on the course, but it only displays 10 students currently. I have added a button at the bottom of this html table that I want the user to be able to click and be taken to a form to view the full leaderboard.

The problem is, I don't know how to do this, and have no experience using JavaScript. I tried to use things like this:

$url = new moodle_url('/blocks/simple_rank/edit_form.php', array('id' => $courseid));

echo $OUTPUT->single_button($url, 'test', 'get');


However, this didn't work, as the button didn't show up on the form but instead behind the header of the local moodle page and when clicked it did not get taken to the form that I wanted it to.

Apologies for the presumably stupid question, but any help and (simple) explanation would be greatly appreciated!

Thanks,

Sean.


Average of ratings: -
In reply to Sean Thornber

Re: How do I handle a button being clicked?

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
It shouldn't need JS to work. Your button has to be defined in the 'content' of the block so you need to append output from the single_button() function to the list e.g. $content = $mystudentlist . $OUTPUT->single_button(.....) ;