Skip to content

Commit

Permalink
Add validation for step form
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Oct 23, 2024
1 parent 66b8e09 commit 57105e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions classes/local/form/form_step_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
8 changes: 8 additions & 0 deletions step/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 57105e5

Please sign in to comment.