Formslib bug?

Formslib bug?

by Davo Smith -
Number of replies: 2
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

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?

Average of ratings: -
In reply to Davo Smith

Re: Formslib bug?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Can't you pass the course into the form constructor, rather than the set_date method?

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Formslib bug?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You're right - I'd completely missed the 'customdata' parameter in the form constructor (all the forms I've written until now have worked fine without needing any parameters at all).

Thanks for the help!