aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-01-14 12:04:02 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-01-14 12:04:02 +0100
commitd57c43d39769c7f29df85684428f6e120d65c103 (patch)
tree148a785925b7e958bc6db8d52acb57bbfac22608
parent190c2e989a27bcd1ec9592f0d22faf32b496ed52 (diff)
downloadforums-d57c43d39769c7f29df85684428f6e120d65c103.tar
forums-d57c43d39769c7f29df85684428f6e120d65c103.tar.gz
forums-d57c43d39769c7f29df85684428f6e120d65c103.tar.bz2
forums-d57c43d39769c7f29df85684428f6e120d65c103.tar.xz
forums-d57c43d39769c7f29df85684428f6e120d65c103.zip
[ticket/11201] Move error message generation to type class
PHPBB3-11201
-rw-r--r--phpBB/phpbb/profilefields/profilefields.php44
-rw-r--r--phpBB/phpbb/profilefields/type/type_bool.php2
-rw-r--r--phpBB/phpbb/profilefields/type/type_date.php6
-rw-r--r--phpBB/phpbb/profilefields/type/type_dropdown.php4
-rw-r--r--phpBB/phpbb/profilefields/type/type_int.php4
-rw-r--r--phpBB/phpbb/profilefields/type/type_interface.php2
-rw-r--r--phpBB/phpbb/profilefields/type/type_string_common.php18
7 files changed, 25 insertions, 55 deletions
diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php
index 362859d57a..9edefdcca5 100644
--- a/phpBB/phpbb/profilefields/profilefields.php
+++ b/phpBB/phpbb/profilefields/profilefields.php
@@ -190,48 +190,8 @@ class profilefields
if (($cp_result = $profile_field->validate_profile_field($check_value, $row)) !== false)
{
- // If not and only showing common error messages, use this one
- $error = '';
- switch ($cp_result)
- {
- case 'FIELD_INVALID_DATE':
- case 'FIELD_INVALID_VALUE':
- case 'FIELD_REQUIRED':
- $error = $this->user->lang($cp_result, $row['lang_name']);
- break;
-
- case 'FIELD_TOO_SHORT':
- case 'FIELD_TOO_SMALL':
- $error = $this->user->lang($cp_result, (int) $row['field_minlen'], $row['lang_name']);
- break;
-
- case 'FIELD_TOO_LONG':
- case 'FIELD_TOO_LARGE':
- $error = $this->user->lang($cp_result, (int) $row['field_maxlen'], $row['lang_name']);
- break;
-
- case 'FIELD_INVALID_CHARS':
- switch ($row['field_validation'])
- {
- case '[0-9]+':
- $error = $this->user->lang($cp_result . '_NUMBERS_ONLY', $row['lang_name']);
- break;
-
- case '[\w]+':
- $error = $this->user->lang($cp_result . '_ALPHA_ONLY', $row['lang_name']);
- break;
-
- case '[\w_\+\. \-\[\]]+':
- $error = $this->user->lang($cp_result . '_SPACERS_ONLY', $row['lang_name']);
- break;
- }
- break;
- }
-
- if ($error != '')
- {
- $cp_error[] = $error;
- }
+ // If the result is not false, it's an error message
+ $cp_error[] = $cp_result;
}
}
$this->db->sql_freeresult($result);
diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php
index 7edb2ff2c6..c492e2bb81 100644
--- a/phpBB/phpbb/profilefields/type/type_bool.php
+++ b/phpBB/phpbb/profilefields/type/type_bool.php
@@ -89,7 +89,7 @@ class type_bool implements type_interface
if (!$field_value && $field_data['field_required'])
{
- return 'FIELD_REQUIRED';
+ return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php
index e7f1e9543e..48fe651d17 100644
--- a/phpBB/phpbb/profilefields/type/type_date.php
+++ b/phpBB/phpbb/profilefields/type/type_date.php
@@ -114,17 +114,17 @@ class type_date implements type_interface
if ((!$day || !$month || !$year) && $field_data['field_required'])
{
- return 'FIELD_REQUIRED';
+ return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
}
if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
{
- return 'FIELD_INVALID_DATE';
+ return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']);
}
if (checkdate($month, $day, $year) === false)
{
- return 'FIELD_INVALID_DATE';
+ return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']);
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php
index cfc8b289da..0b7ee88217 100644
--- a/phpBB/phpbb/profilefields/type/type_dropdown.php
+++ b/phpBB/phpbb/profilefields/type/type_dropdown.php
@@ -90,12 +90,12 @@ class type_dropdown implements type_interface
if (!isset($this->profilefields->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value]))
{
- return 'FIELD_INVALID_VALUE';
+ return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']);
}
if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
{
- return 'FIELD_REQUIRED';
+ return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php
index 5aaa0036f7..0bb9d2049b 100644
--- a/phpBB/phpbb/profilefields/type/type_int.php
+++ b/phpBB/phpbb/profilefields/type/type_int.php
@@ -80,11 +80,11 @@ class type_int implements type_interface
if ($field_value < $field_data['field_minlen'])
{
- return 'FIELD_TOO_SMALL';
+ return $this->user->lang('FIELD_TOO_SMALL', (int) $row['field_minlen'], $row['lang_name']);
}
else if ($field_value > $field_data['field_maxlen'])
{
- return 'FIELD_TOO_LARGE';
+ return $this->user->lang('FIELD_TOO_LARGE', (int) $row['field_maxlen'], $row['lang_name']);
}
return false;
diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php
index 57f495ec9a..36dfb5686f 100644
--- a/phpBB/phpbb/profilefields/type/type_interface.php
+++ b/phpBB/phpbb/profilefields/type/type_interface.php
@@ -50,7 +50,7 @@ interface type_interface
*
* @param mixed $field_value Field value to validate
* @param array $field_data Array with requirements of the field
- * @return mixed String with key of the error language string, false otherwise
+ * @return mixed String with the error message
*/
public function validate_profile_field(&$field_value, $field_data);
diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php
index c026d93948..46e44fa85a 100644
--- a/phpBB/phpbb/profilefields/type/type_string_common.php
+++ b/phpBB/phpbb/profilefields/type/type_string_common.php
@@ -44,16 +44,16 @@ abstract class type_string_common
}
else if (trim($field_value) === '' && $field_data['field_required'])
{
- return 'FIELD_REQUIRED';
+ return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']);
}
if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
{
- return 'FIELD_TOO_SHORT';
+ return $this->user->lang('FIELD_TOO_SHORT', (int) $row['field_minlen'], $row['lang_name']);
}
else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
{
- return 'FIELD_TOO_LONG';
+ return $this->user->lang('FIELD_TOO_LONG', (int) $row['field_maxlen'], $row['lang_name']);
}
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
@@ -61,7 +61,17 @@ abstract class type_string_common
$field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value);
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
{
- return 'FIELD_INVALID_CHARS';
+ switch ($row['field_validation'])
+ {
+ case '[0-9]+':
+ return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $row['lang_name']);
+
+ case '[\w]+':
+ return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $row['lang_name']);
+
+ case '[\w_\+\. \-\[\]]+':
+ return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $row['lang_name']);
+ }
}
}