/moodle/user/profile/index_category_form.php
PHP | 47 lines | 28 code | 15 blank | 4 comment | 1 complexity | ef3e80b901db4de1ceb98563ec11a36c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0
- <?php //$Id: index_category_form.php,v 1.3.4.3 2009/09/26 17:43:03 arborrow Exp $
- require_once($CFG->dirroot.'/lib/formslib.php');
- class category_form extends moodleform {
- // Define the form
- function definition () {
- global $USER, $CFG;
- $mform =& $this->_form;
- $strrequired = get_string('required');
- /// Add some extra hidden fields
- $mform->addElement('hidden', 'id');
- $mform->setType('id', PARAM_INT);
- $mform->addElement('hidden', 'action', 'editcategory');
- $mform->setType('action', PARAM_ACTION);
- $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
- $mform->setType('name', PARAM_MULTILANG);
- $mform->addRule('name', $strrequired, 'required', null, 'client');
- $this->add_action_buttons(true);
- } /// End of function
- /// perform some moodle validation
- function validation($data, $files) {
- global $CFG;
- $errors = parent::validation($data, $files);
- $data = (object)$data;
- $category = get_record('user_info_category', 'id', $data->id);
- /// Check the name is unique
- if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
- $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
- }
- return $errors;
- }
- }
- ?>