Skip to content

Commit

Permalink
Generate the URL in the FormCaptcha class
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Feb 25, 2023
1 parent 7fc8cca commit e1cea31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions core-bundle/src/Resources/contao/forms/FormCaptcha.php
Expand Up @@ -223,6 +223,21 @@ protected function getHash()
return $this->arrCaptcha['hashes'][0];
}

/**
* Get the AJAX URL
*
* @return string The AJAX URL
*/
protected function getAjaxUrl()
{
$container = System::getContainer();

return $container->get('router')->generate(
'contao_frontend_captcha',
array('_locale' => $container->get('request_stack')->getCurrentRequest()->getLocale())
);
}

/**
* Generate the label and return it as string
*
Expand Down
Expand Up @@ -35,7 +35,7 @@
p.style.display = 'none';

setTimeout(() => {
fetch(<?= json_encode(Contao\System::getContainer()->get('router')->generate('contao_frontend_captcha', ['_locale' => Contao\System::getContainer()->get('request_stack')->getCurrentRequest()->getLocale()])) ?>).then((r) => r.json()).then((d) => {
fetch(<?= json_encode($this->getAjaxUrl()) ?>).then(r => r.json()).then(d => {
e.value = d.sum;
e.form.elements[<?= json_encode($this->name.'_hash') ?>].value = d.hash;
document.getElementById('captcha_text_<?= $this->id ?>').textContent = d.question;
Expand Down

0 comments on commit e1cea31

Please sign in to comment.