I'm trying to work out if this is a bug in formslib, or if I'm just trying to do something I shouldn't.
I've got a form where some of the controls can't be created until the form data is loaded (they are generated from the course contents, so the 'course' field has to be passed in before I can create them). I use the 'definition_after_data' function to create these fields and then finish by calling the 'add_action_buttons' function to add the 'submit' and 'cancel' buttons after defining these extra fields (I wanted the buttons at the bottom of my form).
Unfortunately this stops the 'cancel' button from working, because of the following sequence:
$mform->set_data($settinga);
if ($mform->is_cancelled()) { // <== check for cancelled form here
redirect($returl);
}
// snipped out code to process the submitted form
$mform->display(); // <== 'definition_after_data' called inside here (to create the cancel button)
The best fix I've found so far, is to override the 'is_cancelled' function, within my form code, to specifically look for a 'cancel' param (rather than looping through the 'cancelbuttons' array), as I know that in my case there will only be one 'cancel' button and it is called 'cancel'.
Has anyone got a better solution?