Get error array after mform validation

Get error array after mform validation

by Nicolas Martignoni -
Number of replies: 1
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi,

I've got a mform() with a validation() function, which defines two elements in the $errors array, and would like to customize the error message output depending on the error(s) triggered. Printing out the $mform object shows me the (protected) _error array, but I'd like to get this when using the form.

Is there a way to get the error array once the validation has failed? See this discussion too, that asked the same question.

Average of ratings: -
In reply to Nicolas Martignoni

Re: Get error array after mform validation

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Tim Hunt and Paul Holden gave me the answer on the dev chat. Warm thanks to both of you!

Solution: just respect the basic usage for mforms, specifically call "display()" after "get_data()". Then the errors get displayed automatically.

See https://docs.moodle.org/dev/lib/formslib.php_Usage, especially section "Basic Usage in A Normal Page".