To use Moodle's formslib to define a form, you need to extend the class moodleform:
require_once("$CFG->libdir/formslib.php"); class myproject_form extends moodleform {
The moodleform
class does not extend a QuickForm class, but rather contains one in one of its properties. The moodleform_form
property contains the specific QuickForm object.
When you extend the moodleform
property, you typically set a variable to the _form
property so that you can access the formslib functions. You will almost always see this code in a class that extends the moodleform
class:
function definition() { $mform =& $this->_form;
This makes the formslib object available in the easier-to-use $mform
variable for the remainder of the function.
To create a form, your class only needs to provide the definition
function. This function adds all of the form elements that you require for your form. There are many other functions that you can provide, but definition
is the only one that you need to...