Skip to content

Commit

Permalink
MDL-71954 calendar: improve form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Jul 20, 2021
1 parent 8453fe0 commit c96d24b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions calendar/classes/local/event/forms/managesubscriptions.php
Expand Up @@ -49,7 +49,7 @@ public function definition() {

// Name.
$mform->addElement('text', 'name', get_string('subscriptionname', 'calendar'), array('maxsize' => '255', 'size' => '40'));
$mform->addRule('name', get_string('required'), 'required');
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);

// Import from (url | importfile).
Expand Down Expand Up @@ -125,12 +125,16 @@ public function validation($data, $files) {
}
}
} else if (($data['importfrom'] == CALENDAR_IMPORT_FROM_URL)) {
// Clean input calendar url.
$url = clean_param($data['url'], PARAM_URL);
try {
calendar_get_icalendar($url);
} catch (\moodle_exception $e) {
$errors['url'] = get_string('errorinvalidicalurl', 'calendar');
if (empty($data['url'])) {
$errors['url'] = get_string('errorrequiredurlorfile', 'calendar');
} else {
// Clean input calendar url.
$url = clean_param($data['url'], PARAM_URL);
try {
calendar_get_icalendar($url);
} catch (\moodle_exception $e) {
$errors['url'] = get_string('errorinvalidicalurl', 'calendar');
}
}
} else {
// Shouldn't happen.
Expand Down

0 comments on commit c96d24b

Please sign in to comment.