Get error array after mform validation

Get error array after mform validation

von Nicolas Martignoni -
Anzahl Antworten: 1
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Plugin developers Nutzerbild von Testers Nutzerbild von 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.

Als Antwort auf Nicolas Martignoni

Re: Get error array after mform validation

von Nicolas Martignoni -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Plugin developers Nutzerbild von Testers Nutzerbild von 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".