MDL-8096 - fixed use of formslib in custom profile field gui

This commit is contained in:
skodak 2007-01-25 19:36:47 +00:00
parent 4332512e07
commit 478caed8e1
5 changed files with 28 additions and 34 deletions

View File

@ -4,7 +4,9 @@ class profile_field_menu extends profile_field_base {
function init() {
/// Param 1 for menu type is the options
if (($options = explode("\n", $this->field->param1)) === false) {
if (empty($this->field->param1)) {
$options = array();
} else if (($options = explode("\n", $this->field->param1)) === false) {
$options = array();
}
$this->options = $options;

View File

@ -110,7 +110,8 @@ if ( ($action == 'editcategory' )) {
require_once('index_category_form.php');
$categoryform = new category_form(null, compact('category'));
$categoryform = new category_form(null);
$categoryform->set_data($category);
if ($categoryform->is_cancelled()) {
redirect($redirect);
exit;
@ -153,7 +154,8 @@ if ( ($action == 'editcategory' )) {
} elseif ( $action == 'editfield' ) {
require_once('index_field_form.php');
$fieldform = new field_form(null, compact('field'));
$fieldform = new field_form(null, $field->datatype);
$fieldform->set_data($field);
if ($fieldform->is_cancelled()) {
redirect($redirect);
exit;

View File

@ -8,41 +8,34 @@ class category_form extends moodleform {
function definition () {
global $USER, $CFG;
$mform =& $this->_form;
$renderer =& $mform->defaultRenderer();
$category = $this->_customdata['category'];
$mform =& $this->_form;
$strrequired = get_string('required');
/// Add some extra hidden fields
$mform->addElement('hidden', 'id', $category->id);
$mform->addElement('hidden', 'id');
$mform->addElement('hidden', 'action', 'editcategory');
$mform->addElement('hidden', 'sesskey', $USER->sesskey);
$mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
$mform->setType('name', PARAM_MULTILANG);
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setDefault('name', $category->name);
$this->add_action_buttons(true);
} /// End of function
function definition_after_data () {
/// nothing yet
}
/// perform some moodle validation
function validation ($data) {
global $CFG;
$data = (object)$data;
$err = array();
$category = get_record('user_info_category', 'id', $data->id);
/// Check the name is unique
if (($category = get_record('user_info_category', 'name', $data->name)) and ($category->id <> $data->id)) {
if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
$err['name'] = get_string('profilecategorynamenotunique', 'admin');
}

View File

@ -8,29 +8,26 @@ class field_form extends moodleform {
function definition () {
global $USER, $CFG;
$mform =& $this->_form;
$renderer =& $mform->defaultRenderer();
$field = $this->_customdata['field'];
$mform =& $this->_form;
$fieldtype = $this->_customdata;
$strrequired = get_string('required');
/// Add some extra hidden fields
$mform->addElement('hidden', 'id', $field->id);
$mform->addElement('hidden', 'id');
$mform->addElement('hidden', 'action', 'editfield');
$mform->addElement('hidden', 'type', $field->datatype);
$mform->addElement('hidden', 'oldcategory', $field->categoryid);
$mform->addElement('hidden', 'datatype', $field->datatype);
$mform->addElement('hidden', 'sesskey', $USER->sesskey);
$mform->addElement('hidden', 'type', $fieldtype);
$mform->addElement('hidden', 'oldcategory');
$mform->addElement('hidden', 'datatype');
$mform->addElement('hidden', 'sesskey');
/// Everything else is dependant on the data type
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
$newfield = 'profile_field_'.$field->datatype;
$formfield = new $newfield($field->id);
require_once($CFG->dirroot.'/user/profile/field/'.$fieldtype.'/field.class.php');
$newfield = 'profile_field_'.$fieldtype;
$formfield = new $newfield();
$formfield->edit_field($mform);
/// override the defaults with the user settings
$this->set_data($field);
$this->add_action_buttons(true);
@ -47,12 +44,12 @@ class field_form extends moodleform {
global $CFG;
$data = (object)$data;
$field = $this->_customdata['field'];
$fieldtype = $this->_customdata;
/// Everything else is dependant on the data type
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
$newfield = 'profile_field_'.$field->datatype;
$formfield = new $newfield($field->id);
require_once($CFG->dirroot.'/user/profile/field/'.$fieldtype.'/field.class.php');
$newfield = 'profile_field_'.$fieldtype;
$formfield = new $newfield();
$err = $formfield->edit_validate($data);
if (count($err) == 0){

View File

@ -212,7 +212,7 @@ class profile_field_base {
$form->addElement('selectyesno', 'locked', get_string('profilelocked', 'admin'));
$form->setType('locked', PARAM_BOOL);
unset($choices);
$choices = array();
$choices[0] = get_string('profilevisiblenone', 'admin');
$choices[1] = get_string('profilevisibleprivate', 'admin');
$choices[2] = get_string('profilevisibleall', 'admin');
@ -221,7 +221,7 @@ class profile_field_base {
$form->setDefault('visible', 2);
$form->setHelpButton('visible', array('profilevisible', get_string('profilevisible','admin')));
unset($choices);
$choices = array();
$choices = profile_list_categories();
$form->addElement('select', 'categoryid', get_string('profilecategory', 'admin'), $choices);
$form->setType('categoryid', PARAM_INT);