From 587bd3a311c4d25354a9accf991d88e91b29becd Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 17:40:32 +1100 Subject: [PATCH] Fix Cancel button on Edit form. --- classes/form/outage/edit.php | 10 ++++++++-- edit.php | 14 +++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index 96edaa2..7fb7d93 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -163,10 +163,16 @@ class edit extends moodleform { $this->_form->addElement('html', $OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'), 'notifywarning')); } - - $this->add_action_buttons(); } else { throw new coding_exception('$outage must be an outage object.', $outage); } } + + /** + * {@inheritDoc} + * @see moodleform::definition_after_data() + */ + public function definition_after_data() { + $this->add_action_buttons(); + } } diff --git a/edit.php b/edit.php index 5cd25f8..0d7cb24 100644 --- a/edit.php +++ b/edit.php @@ -38,11 +38,15 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php')); $mform = new edit(); -if ($mform->is_cancelled()) { - redirect(new moodle_url('/auth/outage/manage.php')); -} else if ($outage = $mform->get_data()) { - $id = outagedb::save($outage); - redirect(new moodle_url('/auth/outage/manage.php')); +if ($mform->is_submitted()) { + $mform->is_validated(); + + if ($mform->is_cancelled()) { + redirect(new moodle_url('/auth/outage/manage.php')); + } else if ($outage = $mform->get_data()) { + $id = outagedb::save($outage); + redirect(new moodle_url('/auth/outage/manage.php')); + } } $clone = optional_param('clone', 0, PARAM_INT);