Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-71508

Allow minimum datetime validation for user profile fields

    XMLWordPrintable

Details

    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • Hide

      1. For PHPUnit testing run the new test

      user/profile/field/datetime/tests/form_test.php

      2. For manual testing.
      2.1. Add a new user profile field of type 'datetime' with these parameters:

      user/profile/index.php?id=0&action=editfield&datatype=datetime

      shortname: 'minimumdate'
      name: 'Date of birth'
      datatype: 'datetime'
      descriptionformat: FORMAT_HTML
      categoryid: '1'
      required: '1'
      locked: '0'
      visible: '1'
      forceunique: '0'
      signup: '1'
      defaultdata: 0
      defaultdataformat: FORMAT_MOODLE
      startyear: ''
      endyear: ''
      param1: '1900'
      param2: '2020'
      param3: ''
      param4: 'minimumdatetime=18 years;minimumdatetimeerror=Date of birth must be greater than 18'
      param5: ''

      2.2. Test the creation of a new account via the login screen.

      if you enter a 'Date of birth' which is less than 18 years the 'Date of birth' error should be displayed.
      if you enter a 'Date of birth' which is 18 years or greater the 'Date of birth' error should not be displayed.

      Show
      1. For PHPUnit testing run the new test user/profile/field/datetime/tests/form_test.php 2. For manual testing. 2.1. Add a new user profile field of type 'datetime' with these parameters: user/profile/index.php?id=0&action=editfield&datatype=datetime shortname: 'minimumdate' name: 'Date of birth' datatype: 'datetime' descriptionformat: FORMAT_HTML categoryid: '1' required: '1' locked: '0' visible: '1' forceunique: '0' signup: '1' defaultdata: 0 defaultdataformat: FORMAT_MOODLE startyear: '' endyear: '' param1: '1900' param2: '2020' param3: '' param4: 'minimumdatetime=18 years;minimumdatetimeerror=Date of birth must be greater than 18' param5: '' 2.2. Test the creation of a new account via the login screen. if you enter a 'Date of birth' which is less than 18 years the 'Date of birth' error should be displayed. if you enter a 'Date of birth' which is 18 years or greater the 'Date of birth' error should not be displayed.

    Description

      The proposed amendment provides validation for a minimum datetime value for the profile form fields. The solution is generic and allows specifying custom validation parameters via the param4 field of the user_info_field table.

      Here is an example usage for parameters via the param4 field which validates the date is at least 18 years:

      param4 = 'minimumdatetime=18 years;minimumdatetimeerror=Minimum test date required'

      Additional change implemented to the UI to include a new field called "Data validation parameters" which allows configuring the param4 field manually.

      Attachments

        1. ~WRD0000.jpg
          ~WRD0000.jpg
          0.8 kB
        2. CONTRIB-8453 patch.txt
          16 kB
        3. editdate_withoutpatch.png
          editdate_withoutpatch.png
          61 kB
        4. editdate_withpatch.png
          editdate_withpatch.png
          72 kB
        5. image001.png
          image001.png
          6 kB
        6. image001.png
          image001.png
          6 kB
        7. image002.png
          image002.png
          0.3 kB
        8. image002.png
          image002.png
          0.3 kB
        9. image-2022-08-31-12-43-07-294.png
          image-2022-08-31-12-43-07-294.png
          50 kB
        10. image-2022-09-17-14-47-12-753.png
          image-2022-09-17-14-47-12-753.png
          93 kB

        Activity

          People

            Unassigned Unassigned
            emanoylov Emanoil Manoylov
            Amaia Anabitarte Amaia Anabitarte
            David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 2 minutes
                1h 2m