Created
May 9, 2012 14:28
-
-
Save robertmarsal/2644894 to your computer and use it in GitHub Desktop.
Moodle form that is disabled based on customdata parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once($CFG->dirroot.'/lib/formslib.php'); | |
class my_form extends moodleform{ | |
function definition() { | |
//check if the select must be disabled | |
isset($this->_customdata['disabled_select']) | |
? $disabled = 1 //use numeric booleans for this to work | |
: $disabled = 0; | |
//add a select | |
$options = array('0' => 'first', '1' => 'second'); | |
$this->_form->addElement('select', 'my_select', | |
'This is my select!', $options); | |
//add the disabledIf rule (1 is disabled, 0 is enabled) | |
$this->_form->disabledIf('my_select', $disabled); | |
//add a submit button | |
$this->_form->addElement('submit', 'save_changes', 'Save!'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment