From: Matthias Schmidt Date: Tue, 2 Apr 2019 17:29:42 +0000 (+0200) Subject: Fix issues with captcha form field (validation) X-Git-Tag: 5.2.0_Alpha_1~175 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e560fb02d46a6f8939db91d58263412417786e69;p=GitHub%2FWoltLab%2FWCF.git Fix issues with captcha form field (validation) See #2509 --- 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())); + } } /**