Fix formvalidator when using labels as array

pull/3016/head
Julio 6 years ago
parent e76cd54acc
commit 3255803d82
  1. 8
      main/inc/lib/formvalidator/Element/DatePicker.php
  2. 8
      main/inc/lib/formvalidator/Element/DateRangePicker.php
  3. 8
      main/inc/lib/formvalidator/Element/DateTimePicker.php
  4. 17
      main/inc/lib/formvalidator/Element/HtmlEditor.php
  5. 22
      main/inc/lib/formvalidator/FormValidator.class.php
  6. 8
      main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php
  7. 24
      main/inc/lib/pear/HTML/QuickForm/element.php
  8. 41
      main/inc/lib/pear/HTML/QuickForm/textarea.php

@ -9,11 +9,11 @@
class DatePicker extends HTML_QuickForm_text
{
/**
* @param string $elementName
* @param string $elementLabel
* @param array $attributes
* @param string $elementName
* @param string|array $elementLabel
* @param array $attributes
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null)
public function __construct($elementName, $elementLabel = null, $attributes = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = $elementName;

@ -7,9 +7,13 @@
class DateRangePicker extends HTML_QuickForm_text
{
/**
* Constructor.
* DateRangePicker constructor.
*
* @param string $elementName
* @param string|array $elementLabel
* @param array $attributes
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null)
public function __construct($elementName, $elementLabel = null, $attributes = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = $elementName;

@ -7,9 +7,13 @@
class DateTimePicker extends HTML_QuickForm_text
{
/**
* Constructor.
* DateTimePicker constructor.
*
* @param string $elementName
* @param string|array $elementLabel
* @param array $attributes
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null)
public function __construct($elementName, $elementLabel = null, $attributes = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = $elementName;

@ -19,27 +19,26 @@ class HtmlEditor extends HTML_QuickForm_textarea
/**
* Class Constructor.
*
* @param string $name
* @param string $elementLabel HTML editor label
* @param array $attributes Attributes for the textarea
* @param array $config optional configuration settings for the online editor
* @param string $name
* @param string|array $label HTML editor label
* @param array $attributes Attributes for the textarea
* @param array $config optional configuration settings for the online editor
*/
public function __construct(
$name = null,
$elementLabel = null,
$name,
$label = null,
$attributes = [],
$config = []
) {
if (empty($name)) {
throw new Exception('The html editor needs a name');
throw new \Exception('Name is required');
}
parent::__construct($name, $elementLabel, $attributes);
parent::__construct($name, $label, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'html_editor';
$editor = Container::getHtmlEditor();
if ($editor) {
$this->editor = $editor;
$this->editor->setName($name);

@ -272,11 +272,11 @@ EOT;
}
/**
* @param string $name
* @param string $label
* @param array $attributes
* @param string $name
* @param string|array $label
* @param array $attributes
*
* @return mixed
* @return DateTimePicker
*/
public function addDateTimePicker($name, $label, $attributes = [])
{
@ -285,10 +285,10 @@ EOT;
/**
* @param string $name
* @param string $label
* @param string|array $label
* @param array $attributes
*
* @return HTML_QuickForm_element
* @return DateTimeRangePicker
*/
public function addDateTimeRangePicker($name, $label, $attributes = [])
{
@ -306,10 +306,10 @@ EOT;
}
/**
* @param string $name
* @param string $label
* @param array $attributes
* @param bool $required
* @param string $name
* @param string|array $label
* @param array $attributes
* @param bool $required
*
* @return HTML_QuickForm_textarea
*/
@ -1002,7 +1002,7 @@ EOT;
* Adds a HTML-editor to the form.
*
* @param string $name
* @param string $label The label for the form-element
* @param string|array $label The label for the form-element
* @param bool $required (optional) Is the form-element required (default=true)
* @param bool $fullPage (optional) When it is true, the editor loads completed html code for a full page
* @param array $config (optional) Configuration settings for the online editor

@ -282,7 +282,6 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
$label = $element->getLabel();
$labelForId = $element->getAttribute('id');
$extraLabelClass = $element->getAttribute('extra_label_class');
$icon = $element->getIconToHtml();
if (is_array($label)) {
@ -298,7 +297,6 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
$html = str_replace('{label}', $nameLabel, $this->_templates[$name]);
} else {
$customElementTemplate = $this->getCustomElementTemplate();
if (empty($customElementTemplate)) {
if (method_exists($element, 'getTemplate')) {
$template = $element->getTemplate(
@ -316,7 +314,10 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
} else {
$template = $customElementTemplate;
}
$html = str_replace('{label}', $nameLabel, $template);
$html = $template;
if (is_string($nameLabel)) {
$html = str_replace('{label}', $nameLabel, $template);
}
}
$html = str_replace('{label-for}', $labelFor, $html);
$html = str_replace('{icon}', $icon, $html);
@ -328,6 +329,7 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
} else {
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \t\n\r]*)?/isU", '', $html);
}
if (isset($error)) {
$html = str_replace('{error}', $error, $html);
$html = str_replace('{error_class}', 'error has-error', $html);

@ -84,12 +84,12 @@ class HTML_QuickForm_element extends HTML_Common
/**
* Class constructor
*
* @param string Name of the element
* @param mixed Label(s) for the element
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
* @since 1.0
* @access public
* @param string Name of the element
* @param string|array Label(s) for the element
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
*
* @return void
* @since 1.0
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null)
{
@ -394,7 +394,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public
* @return string
*/
function getLabel()
public function getLabel()
{
return $this->_label;
}
@ -504,7 +504,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public
* @return void
*/
function accept(&$renderer, $required=false, $error=null)
public function accept(&$renderer, $required=false, $error=null)
{
$renderer->renderElement($this, $required, $error);
}
@ -518,7 +518,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access private
* @return void
*/
function _generateId()
public function _generateId()
{
static $idx = 1;
@ -535,7 +535,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public
* @return mixed
*/
function exportValue(&$submitValues, $assoc = false)
public function exportValue(&$submitValues, $assoc = false)
{
$value = $this->_findValue($submitValues);
if (null === $value) {
@ -552,7 +552,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access private
* @return mixed
*/
function _prepareValue($value, $assoc)
public function _prepareValue($value, $assoc)
{
if (null === $value) {
return null;
@ -604,8 +604,6 @@ class HTML_QuickForm_element extends HTML_Common
return $this;
}
/**
* @return null
*/
@ -623,7 +621,7 @@ class HTML_QuickForm_element extends HTML_Common
}
/**
* @return array|null
* @return array
*/
public function calculateSize()
{

@ -45,21 +45,19 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
/**
* Class constructor
*
* @param string Input field name attribute
* @param mixed Label(s) for a field
* @param mixed Either a typical HTML attribute string or an associative array
* @since 1.0
* @access public
* @param string $elementName Input field name attribute
* @param string|array $label Label(s) for a field
* @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
public function __construct(
$elementName = null,
$elementLabel = null,
$label = null,
$attributes = null
) {
$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'form-control';
$columnsSize = isset($attributes['cols-size']) ? $attributes['cols-size'] : null;
$this->setColumnsSize($columnsSize);
parent::__construct($elementName, $elementLabel, $attributes);
parent::__construct($elementName, $label, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'textarea';
$this->_value = null;
@ -73,9 +71,9 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
* @access public
* @return void
*/
function setName($name)
public function setName($name)
{
$this->updateAttributes(array('name'=>$name));
$this->updateAttributes(array('name' => $name));
}
/**
@ -85,7 +83,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
* @access public
* @return string
*/
function getName()
public function getName()
{
return $this->getAttribute('name');
}
@ -98,7 +96,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
* @access public
* @return void
*/
function setValue($value)
public function setValue($value)
{
$this->_value = $value;
}
@ -110,24 +108,11 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
* @access public
* @return string
*/
function getValue()
public function getValue()
{
return $this->_value;
}
/**
* Sets wrap type for textarea element
*
* @param string $wrap Wrap type
* @since 1.0
* @access public
* @return void
*/
function setWrap($wrap)
{
$this->updateAttributes(array('wrap' => $wrap));
}
/**
* Sets height in rows for textarea element
*
@ -136,7 +121,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
* @access public
* @return void
*/
function setRows($rows)
public function setRows($rows)
{
$this->updateAttributes(array('rows' => $rows));
}
@ -149,7 +134,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
* @access public
* @return void
*/
function setCols($cols)
public function setCols($cols)
{
$this->updateAttributes(array('cols' => $cols));
}
@ -166,7 +151,7 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
} else {
return $this->_getTabs() .
return $this->_getTabs().
'<textarea' . $this->_getAttrString($this->_attributes) . '>' .
// because we wrap the form later we don't want the text indented
// Modified by Ivan Tcholakov, 16-MAR-2010.

Loading…
Cancel
Save