Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple instances on the same page won't work #92

Open
fballiano opened this issue Feb 22, 2025 · 1 comment
Open

Multiple instances on the same page won't work #92

fballiano opened this issue Feb 22, 2025 · 1 comment

Comments

@fballiano
Copy link

Hi,
I'm integrating Altcha into an open source ecommerce platform but in some cases I may need 2 instances of the captcha in the same page (eg: checkout page has captcha on the checkout form but there's also the newsletter subscription form in the footer which also should have captcha), but unfortunately the first element that triggers the captcha activation "wins" and it's not possible to have another captcha.

Is this something that could be implemented in the future? Or is there a workaround I could use? I couldn't find any documentation on how to insert/remove a captcha programmatically via javascript.

Thanks!

@fballiano
Copy link
Author

I've used a workaround using the statechange event this way

document.querySelector('altcha-widget').addEventListener('statechange', (ev) => {
    try {
        let payload = ev.detail.payload;
        document.querySelectorAll(form).forEach(form => {
            let hiddenInput = form.querySelector('input[name="NAMEOFTHEALTCHAINPUT"]');
            if (!hiddenInput) {
                hiddenInput = document.createElement('input');
                hiddenInput.setAttribute('type', 'hidden');
                hiddenInput.setAttribute('name', 'NAMEOFTHEALTCHAINPUT');
                form.appendChild(hiddenInput);
            }

            hiddenInput.value = payload;
        });
    } catch (e) {}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant