3 require_once($CFG->dirroot
.'/lib/formslib.php');
5 class category_form
extends moodleform
{
8 function definition () {
11 $mform =& $this->_form
;
13 $strrequired = get_string('required');
15 /// Add some extra hidden fields
16 $mform->addElement('hidden', 'id');
17 $mform->setType('id', PARAM_INT
);
18 $mform->addElement('hidden', 'action', 'editcategory');
19 $mform->setType('action', PARAM_ACTION
);
21 $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
22 $mform->setType('name', PARAM_MULTILANG
);
23 $mform->addRule('name', $strrequired, 'required', null, 'client');
25 $this->add_action_buttons(true);
29 /// perform some moodle validation
30 function validation($data, $files) {
32 $errors = parent
::validation($data, $files);
34 $data = (object)$data;
36 $duplicate = record_exists('user_info_category', 'name', $data->name
);
38 /// Check the name is unique
39 if (!empty($data->id
)) { // we are editing an existing record
40 $olddata = get_record('user_info_category', 'id', $data->id
);
41 // name has changed, new name in use, new name in use by another record
42 $dupfound = (($olddata->name
!== $data->name
) && $duplicate && ($data->id
!= $duplicate->id
));
44 else { // new profile category
45 $dupfound = $duplicate;
49 $errors['name'] = get_string('profilecategorynamenotunique', 'admin');