Field validation code refactored.

This commit is contained in:
Boris Gulay
2016-05-28 00:11:21 +03:00
parent dbadde3333
commit 5ad75ce989

View File

@@ -200,41 +200,39 @@ class ident_switch extends rcube_plugin
} }
// Check field values // Check field values
$noErrors = false; $errMsg = '';
$fLabel = self::ntrim(get_input_value('_ident_switch_form_label', RCUBE_INPUT_POST)); $fLabel = self::ntrim(get_input_value('_ident_switch_form_label', RCUBE_INPUT_POST));
if (strlen($fLabel) > 32) if (strlen($fLabel) > 32)
$rc->output->show_message('ident_switch.err.label.long', 'error'); $errMsg = 'label.long';
else else
{ {
$fHost = self::ntrim(get_input_value('_ident_switch_form_host', RCUBE_INPUT_POST)); $fHost = self::ntrim(get_input_value('_ident_switch_form_host', RCUBE_INPUT_POST));
if (strlen($fHost) > 64) if (strlen($fHost) > 64)
$rc->output->show_message('ident_switch.err.host.long', 'error'); $errMsg = 'host.long';
else else
{ {
$fPort = self::ntrim(get_input_value('_ident_switch_form_port', RCUBE_INPUT_POST)); $fPort = self::ntrim(get_input_value('_ident_switch_form_port', RCUBE_INPUT_POST));
if ($fPort && !ctype_digit($fPort)) if ($fPort && !ctype_digit($fPort))
$rc->output->show_message('ident_switch.err.port.num', 'error'); $errMsg = 'port.num';
else else
{ {
if ($fPort && ($fPort <= 0 || $fPort > 65535)) if ($fPort && ($fPort <= 0 || $fPort > 65535))
$rc->output->show_message('ident_switch.err.port.range', 'error'); $errMsg = 'port.range';
else else
{ {
$fUser = self::ntrim(get_input_value('_ident_switch_form_username', RCUBE_INPUT_POST)); $fUser = self::ntrim(get_input_value('_ident_switch_form_username', RCUBE_INPUT_POST));
if (strlen($fUser) > 64) if (strlen($fUser) > 64)
$rc->output->show_message('ident_switch.err.user.long', 'error'); $errMsg = 'user.long';
else else
{ {
if (!$fUser) if (!$fUser)
$rc->output->show_message('ident_switch.err.user.empty', 'error'); $errMsg = 'user.empty';
else else
{ {
$fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST)); $fDelim = self::ntrim(get_input_value('_ident_switch_form_delimiter', RCUBE_INPUT_POST));
if (strlen($fDelim) > 1) if (strlen($fDelim) > 1)
$rc->output->show_message('ident_switch.err.delim.long', 'error'); $errMsg = 'delim.long';
else
$noErrors = true;
} }
} }
} }
@@ -242,9 +240,10 @@ class ident_switch extends rcube_plugin
} }
} }
if (!$noErrors) if ($errMsg)
{ {
$this->add_texts('localization'); $this->add_texts('localization');
$rc->output->show_message('ident_switch.err.' . $errMsg, 'error');
$args['abort'] = true; $args['abort'] = true;
return $args; return $args;
} }