Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Block formslib: Difference between revisions

From MoodleDocs
No edit summary
Line 2: Line 2:




== Creating a Global Configuration form ==
= Creating a Global Configuration form =


In order to create a global confuration form using formslib, you must create a file <span class="filename">/blocks/BLOCKNAME/config_global_form.php</span>
In order to create a global confuration form using formslib, you must create a file <span class="filename">/blocks/BLOCKNAME/config_global_form.php</span>


In this file a class like needs to be created which follows the naming scheme: block_BLOCKNAME_config_global_form.
In this file a class like needs to be created which follows the naming scheme: block_BLOCKNAME_config_global_form.
 
In your form configuration class you need to implement the block_configuration() method, adding the elements you need with $this->add_config_element(). Using this method means the form elements will be processed when the block configuration is saved.


<pre>
<pre>
Line 29: Line 31:
}
}
</pre>
</pre>
= Custom formslib-style functions =
== add_config_elment ==
This does the same as addElement, except that is also adds the element to the list  of form elements which need to be saved by the block configuration
== set_config_default ==
This will either

Revision as of 20:01, 29 April 2007

(This is currently a proposal and isn't available for use).


Creating a Global Configuration form

In order to create a global confuration form using formslib, you must create a file /blocks/BLOCKNAME/config_global_form.php

In this file a class like needs to be created which follows the naming scheme: block_BLOCKNAME_config_global_form.

In your form configuration class you need to implement the block_configuration() method, adding the elements you need with $this->add_config_element(). Using this method means the form elements will be processed when the block configuration is saved.

require_once $CFG->dirroot .'/blocks/block_config_global_form.php';

class block_BLOCKNAME_config_global_form extends block_config_global_form {

    function block_configuration(&$mform){

        // add a html editor text field
        $this->add_config_element('htmleditor', 'block_BLOCKNAME_text', get_string('text','BLOCKNAME'));

        // set the default value, this will set the default value
        // or set the $CFG value for the same name, if it exists
        $this->set_config_default('block_BLOCKNAME_text', 'mydefault');

        // set an appropiate PARAM type
        $mform->setType('block_BLOCKNAME_text', PARAM_NOTAGS);

    }

}


Custom formslib-style functions

add_config_elment

This does the same as addElement, except that is also adds the element to the list of form elements which need to be saved by the block configuration

set_config_default

This will either