Skip to content

Instantly share code, notes, and snippets.

@robertmarsal
Created May 9, 2012 14:28
Show Gist options
  • Save robertmarsal/2644894 to your computer and use it in GitHub Desktop.
Save robertmarsal/2644894 to your computer and use it in GitHub Desktop.
Moodle form that is disabled based on customdata parameters
<?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