1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 12:03:21 +01:00

[ticket/11538] Add optional switch as argument to hex colour validation

The value of $optional will decide whether an empty string will be
treated as incorrect input or if it is allowed. The optional argument
will default to false and therefore treat an empty string as incorrect
unless explicitly told to not do so.

PHPBB3-11538
This commit is contained in:
Marc Alexander 2013-05-19 17:45:45 +02:00
parent e49b4543de
commit cd1da92d85
3 changed files with 7 additions and 5 deletions

View File

@ -421,7 +421,7 @@ class acp_groups
*/
$validation_checks = array(
'max_recipients' => array('num', false, 0, 16777215),
'colour' => array('hex_colour'),
'colour' => array('hex_colour', true),
);
if ($validation_error = validate_data($submit_ary, $validation_checks))

View File

@ -1903,14 +1903,16 @@ function validate_jabber($jid)
* Validate hex colour value
*
* @param string $colour The hex colour value
* @return bool|string Error message if colour value is incorrect, false if it
* @param bool $optional Whether the colour value is optional. True if an empty
* string will be accepted as correct input, false if not.
* @return bool|string Error message if colour value is incorrect, false if it
* fits the hex colour code
*/
function phpbb_validate_hex_colour($colour)
function phpbb_validate_hex_colour($colour, $optional = false)
{
if (empty($colour))
{
return false;
return (($optional) ? false : 'WRONG_DATA');
}
if (!preg_match('/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/', $colour))

View File

@ -596,7 +596,7 @@ class ucp_groups
}
// Validate submitted colour value
if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour'))))
if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour', true))))
{
// Replace "error" string with its real, localised form
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));