diff --git a/classes/local/form/form_step_instance.php b/classes/local/form/form_step_instance.php index 8b5503ec..d7c93228 100644 --- a/classes/local/form/form_step_instance.php +++ b/classes/local/form/form_step_instance.php @@ -191,4 +191,22 @@ public function definition_after_data() { } } + /** Validate the form. + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array of "element_name"=>"error_description" if there are errors, + * or an empty array if everything is OK (true allowed for backwards compatibility too). + * @throws \coding_exception + */ + public function validation($data, $files) { + $error = parent::validation($data, $files); + if (empty($data['instancename'])) { + $error['instancename'] = get_string('required'); + } + + $this->lib->extend_add_instance_form_validation($error, $data); + + return $error; + } + } diff --git a/step/lib.php b/step/lib.php index 582ab129..18d8e3bf 100644 --- a/step/lib.php +++ b/step/lib.php @@ -134,6 +134,14 @@ public function extend_add_instance_form_definition($mform) { public function extend_add_instance_form_definition_after_data($mform, $settings) { } + /** + * This method can be overriden, to add additional data validation to the instance form. + * @param array $error Array containing all errors. + * @param array $data Data passed from the moodle form to be validated + */ + public function extend_add_instance_form_validation(&$error, $data) { + } + /** * This method can be overridden. It is called when a course and the * corresponding process get deleted.