Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for step form #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions classes/local/form/form_step_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,28 @@ 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) {
// Default form validation.
$error = parent::validation($data, $files);

// Required instance name for tool_lifecycle_step table.
if (empty($data['instancename'])) {
$error['instancename'] = get_string('required');
}

// Allow the subplugin to add its own validation.
$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