Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-28483 URL adding validation checks and changing field externalurl…

… to not-null
  • Loading branch information...
commit 503581b5d07a799185f19d633428eb2778cfa9ba 1 parent 9cdadbc
Ankit Agarwal ankitagarwal authored
Showing with 12 additions and 0 deletions.
  1. +1 −0  mod/url/lang/en/url.php
  2. +11 −0 mod/url/mod_form.php
1  mod/url/lang/en/url.php
View
@@ -45,6 +45,7 @@
$string['externalurl'] = 'External URL';
$string['framesize'] = 'Frame height';
$string['chooseavariable'] = 'Choose a variable...';
+$string['invalidurl'] = 'Entered URL is invalid';
$string['modulename'] = 'URL';
$string['modulenameplural'] = 'URLs';
$string['neverseen'] = 'Never seen';
11 mod/url/mod_form.php
View
@@ -50,6 +50,7 @@ function definition() {
//-------------------------------------------------------
$mform->addElement('header', 'content', get_string('contentheader', 'url'));
$mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), array('usefilepicker'=>true));
+ $mform->addRule('externalurl', null, 'required', null, 'client');
//-------------------------------------------------------
$mform->addElement('header', 'optionssection', get_string('optionsheader', 'url'));
@@ -164,4 +165,14 @@ function data_preprocessing(&$default_values) {
}
}
+ function validation($data, $files) {
+ $errors = parent::validation($data, $files);
+ //Validating Entered url
+ $data['externalurl'] = clean_param($data['externalurl'], PARAM_URL);
+ if (empty($data['externalurl'])) {
+ $errors['externalurl'] = get_string('invalidurl', 'url');
+ }
+ return $errors;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.