Add Formvalidator element of type URL - refs BT#9889 #TMI

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 05a764c4b3
commit aa3d79d40e
  1. 10
      main/inc/lib/extra_field.lib.php
  2. 31
      main/inc/lib/formvalidator/Element/Url.php
  3. 19
      main/inc/lib/formvalidator/FormValidator.class.php

@ -60,6 +60,7 @@ class ExtraField extends Model
const FIELD_TYPE_FILE_IMAGE = 16;
const FIELD_TYPE_FLOAT = 17;
const FIELD_TYPE_FILE = 18;
const FIELD_TYPE_VIDEO_URL = 19;
public $type = 'user';
public $pageName;
@ -333,6 +334,7 @@ class ExtraField extends Model
$types[self::FIELD_TYPE_FILE_IMAGE] = get_lang('FieldTypeFileImage');
$types[self::FIELD_TYPE_FLOAT] = get_lang('FieldTypeFloat');
$types[self::FIELD_TYPE_FILE] = get_lang('FieldTypeFile');
$types[self::FIELD_TYPE_VIDEO_URL] = get_lang('FieldTypeVideoUrl');
switch ($handler) {
case 'course':
@ -1437,6 +1439,14 @@ EOF;
}
}
break;
case ExtraField::FIELD_TYPE_VIDEO_URL:
$form->addUrl(
"extra_{$field_details['variable']}",
$field_details['display_text'],
false,
['placeholder' => 'https://']
);
break;
}
}
}

@ -0,0 +1,31 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Url element
*
* Class Url
*/
class Url extends HTML_QuickForm_text
{
/**
* Constructor of Url class
* @param type $elementName
* @param type $elementLabel
* @param type $attributes
*/
public function Url($elementName = null, $elementLabel = null, $attributes = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = $elementName;
}
$attributes['type'] = 'url';
$attributes['class'] = 'form-control';
parent::__construct($elementName, $elementLabel, $attributes);
$this->setType('url');
}
}

@ -973,6 +973,25 @@ EOT;
isset($GLOBALS['_HTML_QuickForm_default_renderer']) ?
$GLOBALS['_HTML_QuickForm_default_renderer'] : null;
}
/**
* Adds a input of type url to the form.
* @param type $name The label for the form-element
* @param type $label The element name
* @param type $required Optional. Is the form-element required (default=true)
* @param type $attributes Optional. List of attributes for the form-element
*/
public function addUrl($name, $label, $required = true, $attributes = array())
{
$this->addElement('url', $name, $label, $attributes);
$this->applyFilter($name, 'trim');
$this->addRule($name, get_lang('InsertAValidUrl'), 'url');
if ($required) {
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
}
}
}
/**

Loading…
Cancel
Save