Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / user / profile / index_category_form.php
blob51c585ccf382e8974259c9f3b71743fee19916a5
1 <?php //$Id$
3 require_once($CFG->dirroot.'/lib/formslib.php');
5 class category_form extends moodleform {
7 // Define the form
8 function definition () {
9 global $USER, $CFG;
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);
25 } /// End of function
27 /// perform some moodle validation
28 function validation($data, $files) {
29 global $CFG;
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');
41 return $errors;