Before performing an operation that may be destructive or time consuming, you want to prompt the user to confirm whether he really wants to do it. There are several pages in the Moodle website that have this feature. While I was learning how they work, I created a minimal example page that seems to include the essential steps. It helped me to create it, so perhaps it might help others.
The example page is attached as danger.php
To use the example page, some other page has to link to it. For example, by clicking a button that is defined by the following code.
$dangerUrl = new moodle_url( '/local/example/danger.php', array( 'id' => 3 ) );
echo $OUTPUT->single_button( $dangerUrl, 'Danger op' );
Comments, corrections, and suggestions welcome.