/** * Adds a NotEmptyValidator to the current element if the "trigger" value is not empty. * The trigger can be configured with $this->properties['triggerPropertyPath'] * * @param \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime * @return void */ protected function requireIfTriggerIsSet(\TYPO3\Form\Core\Runtime\FormRuntime $formRuntime) { if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'newDataSheet') { if ($this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) { $this->addValidator(new \TYPO3\Flow\Validation\Validator\NotEmptyValidator()); } elseif (!$this->authenticationManager->isAuthenticated()) { $this->addValidator(new \TYPO3\Flow\Validation\Validator\NotEmptyValidator()); } else { return; } } elseif ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'editDataSheet') { return; } }
/** * On form submit * * @param \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime * @param mixed $elementValue * @return void */ public function onSubmit(\TYPO3\Form\Core\Runtime\FormRuntime $formRuntime, &$elementValue) { $error = false; if (isset($_POST['g-recaptcha-response'])) { $captcha = $_POST['g-recaptcha-response']; $secretKey = isset($this->settings['googleCaptcha'][$formRuntime->getIdentifier()]['secretkey']) ? $this->settings['googleCaptcha'][$formRuntime->getIdentifier()]['secretkey'] : ''; $ip = $_SERVER['REMOTE_ADDR']; $response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretKey . '&response=' . $captcha . '&remoteip=' . $ip); $responseKeys = json_decode($response, true); if (intval($responseKeys['success']) !== 1) { $error = true; } } else { $error = true; } if ($error) { $processingRule = $this->getRootForm()->getProcessingRule($this->getIdentifier()); $processingRule->getProcessingMessages()->addError(new \TYPO3\Flow\Error\Error('Captcha isn\'t correct', 8734423749)); } }
/** * The values of the submitted form (after validation and property mapping) * * @return array * @api */ public function getFormValues() { return $this->formRuntime->getFormState()->getFormValues(); }