From 793a0a061fdcffc782803ba521f389b61cbc67b8 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Mon, 12 May 2014 15:40:59 +0200 Subject: [PATCH 1/2] Add validation for application name. refs #6129 --- application/forms/Config/LoggingForm.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/application/forms/Config/LoggingForm.php b/application/forms/Config/LoggingForm.php index eff629e09..3683c29b5 100644 --- a/application/forms/Config/LoggingForm.php +++ b/application/forms/Config/LoggingForm.php @@ -30,7 +30,7 @@ namespace Icinga\Form\Config; -use Zend_Config; +use \Zend_Config; use Icinga\Web\Form; use Icinga\Application\Icinga; use Icinga\Web\Form\Validator\WritablePathValidator; @@ -116,7 +116,19 @@ class LoggingForm extends Form 'required' => true, 'label' => t('Application Prefix'), 'helptext' => t('The name of the application by which to prefix syslog messages.'), - 'value' => $loggingConfig->get('application', 'icingaweb') + 'value' => $loggingConfig->get('application', 'icingaweb'), + 'validators' => array( + array( + 'Regex', + false, + array( + 'pattern' => '/^[^\W]+$/', + 'messages' => array( + 'regexNotMatch' => 'The application prefix cannot contain any whitespaces.' + ) + ) + ) + ) ) ); $this->addElement( From ced6e8f78f8c21c3cf5a3a660788a19465a1b6dc Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Mon, 12 May 2014 15:49:38 +0200 Subject: [PATCH 2/2] Initialize all empty ellements with their default values. refs #6098 --- application/forms/Config/LoggingForm.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/application/forms/Config/LoggingForm.php b/application/forms/Config/LoggingForm.php index 3683c29b5..81540a683 100644 --- a/application/forms/Config/LoggingForm.php +++ b/application/forms/Config/LoggingForm.php @@ -163,6 +163,16 @@ class LoggingForm extends Form $this->setSubmitLabel('{{SAVE_ICON}} Save Changes'); } + public function isValid($data) { + foreach ($this->getElements() as $key => $element) { + // Initialize all empty elements with their default values. + if (!isset($data[$key])) { + $data[$key] = $element->getValue(); + } + } + return parent::isValid($data); + } + /** * Return a Zend_Config object containing the state defined in this form *