# Forms and views (laravel-rust-captcha)

> 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…

- Package: laravel-rust-captcha (Laravel for Rust, alpha), crates: `laravel-rust-captcha`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-captcha), [crates.io](https://crates.io/crates/laravel-rust-captcha/0.1.0), [docs.rs](https://docs.rs/laravel-rust-captcha/0.1.0), [Changelog](https://oss.bowerbird.si/captcha/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/SECURITY.md)
- Based on: [mews/captcha](https://github.com/mewebstudio/captcha): The captcha package this ports: profiles, config keys, routes and validation, following version 3.5.1. Its backgrounds and fonts ship with their own licences.
- PHP parity: full (54 covered, 33 diverged, 0 planned of 87 abilities; 44 fixtures; follows mews/captcha 3.5.1; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/captcha/docs/forms/
- Source: https://github.com/bowerbird-si/laravel-rust-captcha/blob/57c677c77d6c928790e0acaf24e0b3f0ff06f29c/docs/forms.md

## 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](https://oss.bowerbird.si/captcha/docs/keyed/) |

`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:

```html
{{ 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:

```html
<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

```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.
