# Invisible CAPTCHA

Invisible mode omits the checkbox. A challenge may still appear when a user
submits. Your server must verify the token just as it does for a normal widget.

## Automatically bind the challenge to a button

A `.katcha` button or input host runs in invisible mode. Supply your site key and
a callback that submits only after success. Replace the `.example` script host
with your deployed Katcha host.

```html
<form id="contact-form" action="/contact" method="post">
  <label>Message <input name="message" required /></label>
  <button type="button" class="katcha" data-site-key="YOUR_SITE_KEY"
          data-lang="en" data-callback="submitContact">Send message</button>
</form>
<script>
  window.submitContact = function (token) {
    const form = document.getElementById('contact-form');
    if (token && form.reportValidity()) form.requestSubmit();
  };
</script>
<script src="https://widget.katcha.eu/1/api.js" async defer></script>
```

The widget adds the hidden `katcha-token` field. The server must reject unverified
submissions, including those that bypass the button.

## Programmatically bind the challenge to a button or invoke the challenge

Use [explicit rendering](/markdown/guide/configuration.md#explicitly-render-katcha) with
`size: 'invisible'`. Keep the returned ID to avoid executing the wrong widget.

## Programmatically invoke the challenge

Validate the form first, then await
[katcha.execute](/markdown/guide/configuration.md#katchaexecutewidgetid). Handle cancellation
and errors; do not accept a browser success as server authorization.

### Example

```html
<form id="message-form" action="/message" method="post">
  <label>Message <input name="message" required /></label>
  <div id="invisible-widget"></div>
  <p id="challenge-status" role="status"></p>
  <button id="send-message" type="button" disabled>Send</button>
</form>
<script>
  window.initializeInvisible = function () {
    const form = document.getElementById('message-form');
    const button = document.getElementById('send-message');
    const status = document.getElementById('challenge-status');
    const widgetId = window.katcha.render('#invisible-widget', {
      site_key: 'YOUR_SITE_KEY',
      lang: 'en',
      size: 'invisible'
    });
    button.disabled = false;
    button.addEventListener('click', async function () {
      if (!form.reportValidity()) return;
      button.disabled = true;
      status.textContent = '';
      try {
        const { katcha_token } = await window.katcha.execute(widgetId);
        if (!katcha_token) throw new Error('Missing challenge token');
        form.requestSubmit();
      } catch (error) {
        status.textContent = 'Challenge not completed. Please try again.';
      } finally {
        button.disabled = false;
      }
    });
  };
</script>
<script src="https://widget.katcha.eu/1/api.js" defer onload="initializeInvisible()"></script>
```

Execution is bound to the button, not a submit handler that calls itself again
through `requestSubmit()`. Ordinary keyboard submission must also be safe: enforce
[verification](/markdown/api/verify.md) at the server regardless of how the request arrives.
