Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… to not-null
  • Loading branch information...
commit 6bcfb5f23b06f2859c6f69966d071e4495047d40 1 parent 263c528
Ankit Agarwal authored September 28, 2011
1  mod/url/lang/en/url.php
@@ -45,6 +45,7 @@
45 45
 $string['externalurl'] = 'External URL';
46 46
 $string['framesize'] = 'Frame height';
47 47
 $string['chooseavariable'] = 'Choose a variable...';
  48
+$string['invalidurl'] = 'Entered URL is invalid';
48 49
 $string['modulename'] = 'URL';
49 50
 $string['modulenameplural'] = 'URLs';
50 51
 $string['neverseen'] = 'Never seen';
11  mod/url/mod_form.php
@@ -50,6 +50,7 @@ function definition() {
50 50
         //-------------------------------------------------------
51 51
         $mform->addElement('header', 'content', get_string('contentheader', 'url'));
52 52
         $mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), array('usefilepicker'=>true));
  53
+        $mform->addRule('externalurl', null, 'required', null, 'client');
53 54
         //-------------------------------------------------------
54 55
         $mform->addElement('header', 'optionssection', get_string('optionsheader', 'url'));
55 56
 
@@ -165,4 +166,14 @@ function data_preprocessing(&$default_values) {
165 166
         }
166 167
     }
167 168
 
  169
+    function validation($data, $files) {
  170
+        $errors = parent::validation($data, $files);
  171
+        //Validating Entered url
  172
+        $data['externalurl'] = clean_param($data['externalurl'], PARAM_URL);
  173
+        if (empty($data['externalurl'])) {
  174
+            $errors['externalurl'] = get_string('invalidurl', 'url');
  175
+        }
  176
+        return $errors;
  177
+    }
  178
+
168 179
 }

0 notes on commit 6bcfb5f

Please sign in to comment.
Something went wrong with that request. Please try again.