Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Forgot password page.
  19   *
  20   * @package    core
  21   * @subpackage auth
  22   * @copyright  2006 Petr Skoda {@link http://skodak.org}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir.'/formslib.php');
  28  require_once($CFG->dirroot.'/user/lib.php');
  29  require_once ('lib.php');
  30  
  31  /**
  32   * Reset forgotten password form definition.
  33   *
  34   * @package    core
  35   * @subpackage auth
  36   * @copyright  2006 Petr Skoda {@link http://skodak.org}
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class login_forgot_password_form extends moodleform {
  40  
  41      /**
  42       * Define the forgot password form.
  43       */
  44      function definition() {
  45          global $USER;
  46  
  47          $mform    = $this->_form;
  48          $mform->setDisableShortforms(true);
  49  
  50          // Hook for plugins to extend form definition.
  51          core_login_extend_forgot_password_form($mform);
  52  
  53          $mform->addElement('header', 'searchbyusername', get_string('searchbyusername'), '');
  54  
  55          $purpose = user_edit_map_field_purpose($USER->id, 'username');
  56          $mform->addElement('text', 'username', get_string('username'), 'size="20"' . $purpose);
  57          $mform->setType('username', PARAM_RAW);
  58  
  59          $submitlabel = get_string('search');
  60          $mform->addElement('submit', 'submitbuttonusername', $submitlabel);
  61  
  62          $mform->addElement('header', 'searchbyemail', get_string('searchbyemail'), '');
  63  
  64          $purpose = user_edit_map_field_purpose($USER->id, 'email');
  65          $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"' . $purpose);
  66          $mform->setType('email', PARAM_RAW_TRIMMED);
  67  
  68          $submitlabel = get_string('search');
  69          $mform->addElement('submit', 'submitbuttonemail', $submitlabel);
  70      }
  71  
  72      /**
  73       * Validate user input from the forgot password form.
  74       * @param array $data array of submitted form fields.
  75       * @param array $files submitted with the form.
  76       * @return array errors occuring during validation.
  77       */
  78      function validation($data, $files) {
  79  
  80          $errors = parent::validation($data, $files);
  81  
  82          // Extend validation for any form extensions from plugins.
  83          $errors = array_merge($errors, core_login_validate_extend_forgot_password_form($data));
  84  
  85          $errors += core_login_validate_forgot_password_data($data);
  86  
  87          return $errors;
  88      }
  89  
  90  }