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->addElement('hidden', 'action', 'editcategory');
19 $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
20 $mform->setType('name', PARAM_MULTILANG
);
21 $mform->addRule('name', $strrequired, 'required', null, 'client');
23 $this->add_action_buttons(true);
27 /// perform some moodle validation
28 function validation($data, $files) {
30 $errors = parent
::validation($data, $files);
32 $data = (object)$data;
34 $category = get_record('user_info_category', 'id', $data->id
);
36 /// Check the name is unique
37 if ($category and ($category->name
!== $data->name
) and (record_exists('user_info_category', 'name', $data->name
))) {
38 $errors['name'] = get_string('profilecategorynamenotunique', 'admin');