PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/moodle/user/profile/index_category_form.php

https://bitbucket.org/geek745/moodle-db2
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
  1. <?php //$Id: index_category_form.php,v 1.3.4.3 2009/09/26 17:43:03 arborrow Exp $
  2. require_once($CFG->dirroot.'/lib/formslib.php');
  3. class category_form extends moodleform {
  4. // Define the form
  5. function definition () {
  6. global $USER, $CFG;
  7. $mform =& $this->_form;
  8. $strrequired = get_string('required');
  9. /// Add some extra hidden fields
  10. $mform->addElement('hidden', 'id');
  11. $mform->setType('id', PARAM_INT);
  12. $mform->addElement('hidden', 'action', 'editcategory');
  13. $mform->setType('action', PARAM_ACTION);
  14. $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
  15. $mform->setType('name', PARAM_MULTILANG);
  16. $mform->addRule('name', $strrequired, 'required', null, 'client');
  17. $this->add_action_buttons(true);
  18. } /// End of function
  19. /// perform some moodle validation
  20. function validation($data, $files) {
  21. global $CFG;
  22. $errors = parent::validation($data, $files);
  23. $data = (object)$data;
  24. $category = get_record('user_info_category', 'id', $data->id);
  25. /// Check the name is unique
  26. if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
  27. $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
  28. }
  29. return $errors;
  30. }
  31. }
  32. ?>