MiniJinja functions
| Function | What | PHP |
|---|---|---|
captcha_src(profile="default") | The image URL, with a random query so browsers don't reuse a cached image | captcha_src($config) |
captcha_img(profile="default", **attrs) | An <img> tag | captcha_img($config, $attrs) |
captcha_field(challenge) | A keyed challenge's image and hidden key field | none; see Keyed challenges |
captcha_img escapes attribute values, keeps only safe attribute names (no on* handlers, style
or srcset), reserves src, and adds alt="captcha" when you don't give an alt. Its output is
marked safe, so don't escape it again:
{{ captcha_img('flat', class='captcha', alt='Type the characters') }}A refresh button
Each image request issues a new challenge, and only the latest one counts. A refresh button only needs a new image URL:
<img id="captcha" src="{{ captcha_src('contact') }}" alt="captcha">
<button type="button" onclick="const i = document.getElementById('captcha');
i.src = i.src.split('?')[0] + '?' + Date.now()">New image</button>From Rust
let url = laravel_rust_captcha::src("contact");
let tag = laravel_rust_captcha::img("contact", [("class", "captcha")]);
For Inertia, pass src("contact") as a prop, as PHP apps pass captcha_src('contact').
After a failed form
A correct answer is used up even when another field fails, so the redirected form needs a new image.
captcha_src() gives a new URL on every render, so the browser loads one. The answer itself is never
flashed back as old input.
Accessibility
An image captcha excludes people who can't see it. Offer another way to reach you next to the form, such as a contact address or a support link. An audio alternative is planned.