From e560fb02d46a6f8939db91d58263412417786e69 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 2 Apr 2019 19:29:42 +0200 Subject: [PATCH] Fix issues with captcha form field (validation) See #2509 --- .../templates/__captchaFormField.tpl | 1 + .../acp/templates/__captchaFormField.tpl | 1 + .../builder/field/CaptchaFormField.class.php | 43 ++++++++++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 com.woltlab.wcf/templates/__captchaFormField.tpl create mode 100644 wcfsetup/install/files/acp/templates/__captchaFormField.tpl diff --git a/com.woltlab.wcf/templates/__captchaFormField.tpl b/com.woltlab.wcf/templates/__captchaFormField.tpl new file mode 100644 index 0000000000..f4202f8f1c --- /dev/null +++ b/com.woltlab.wcf/templates/__captchaFormField.tpl @@ -0,0 +1 @@ +{@$field->getObjectType()->getProcessor()->getFormElement()} diff --git a/wcfsetup/install/files/acp/templates/__captchaFormField.tpl b/wcfsetup/install/files/acp/templates/__captchaFormField.tpl new file mode 100644 index 0000000000..f4202f8f1c --- /dev/null +++ b/wcfsetup/install/files/acp/templates/__captchaFormField.tpl @@ -0,0 +1 @@ +{@$field->getObjectType()->getProcessor()->getFormElement()} diff --git a/wcfsetup/install/files/lib/system/form/builder/field/CaptchaFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/CaptchaFormField.class.php index c3f111ac7c..153ffac4d8 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/CaptchaFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/CaptchaFormField.class.php @@ -1,6 +1,8 @@ getObjectType()->getProcessor(); + public function getHtmlVariables() { + $variables = [ + 'ajaxCaptcha' => $this->getDocument()->isAjax(), + 'captchaID' => $this->getPrefixedId() + ]; - return $captcha->getFormElement(); + if ($this->validationException !== null) { + $variables['errorField'] = $this->validationException->getField(); + $variables['errorType'] = $this->validationException->getType(); + } + + return $variables; } /** @@ -53,6 +73,13 @@ class CaptchaFormField extends AbstractFormField implements IObjectTypeFormNode return 'com.woltlab.wcf.captcha'; } + /** + * @inheritDoc + */ + public function isAvailable() { + return $this->objectType !== null && parent::isAvailable(); + } + /** * @inheritDoc */ @@ -103,7 +130,13 @@ class CaptchaFormField extends AbstractFormField implements IObjectTypeFormNode /** @var ICaptchaHandler $captcha */ $captcha = $this->getObjectType()->getProcessor(); - $captcha->validate(); + try { + $captcha->validate(); + } + catch (UserInputException $e) { + $this->validationException = $e; + $this->addValidationError(new FormFieldValidationError($e->getType())); + } } /** -- 2.20.1