# Button: Forms

> For submit buttons, call `track()` from `useButtonFeedback` in `onSubmit` and spread `buttonProps` on the button. Remove the @ to see the error.

Example: https://hextaui.com/docs/button/examples/form
Component docs: https://hextaui.com/docs/button.md

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/button-form.json
```

This adds `components/examples/button/form.tsx` with the Button component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/button/form.tsx"
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import { useButtonFeedback } from "@/hooks/use-button-feedback"

function wait(ms: number) {
  return new Promise<void>((resolve) => setTimeout(resolve, ms))
}

async function fail(ms: number) {
  await wait(ms)
  throw new Error("Invalid email")
}

export function ButtonForm() {
  const save = useButtonFeedback()
  const [email, setEmail] = React.useState("olivia@example.com")

  return (
    <form
      className="flex w-full max-w-sm items-center gap-2"
      onSubmit={(event) => {
        event.preventDefault()
        save.track(email.includes("@") ? wait(900) : fail(600))
      }}
    >
      <input
        aria-label="Email"
        value={email}
        onChange={(event) => setEmail(event.target.value)}
        className="h-9 min-w-0 flex-1 rounded-md border border-input bg-transparent px-3 text-sm transition-shadow outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-focus-ring focus-visible:outline-hidden pointer-coarse:text-touch"
      />
      <Button
        type="submit"
        {...save.buttonProps}
        successLabel="Subscribed"
        errorLabel="Invalid email"
      >
        Subscribe
      </Button>
    </form>
  )
}
```

## Props in this example

### Button

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `successLabel` | `ReactNode` | `"Done"` |  |
| `errorLabel` | `ReactNode \| (error: unknown) => ReactNode` | `"Failed"` |  |

## More Button examples

- [Variants](https://hextaui.com/docs/button/examples/variants.md)
- [Sizes](https://hextaui.com/docs/button/examples/sizes.md)
- [Pill](https://hextaui.com/docs/button/examples/pill.md)
- [With icon](https://hextaui.com/docs/button/examples/with-icon.md)
- [Disabled](https://hextaui.com/docs/button/examples/disabled.md)
- [Custom labels](https://hextaui.com/docs/button/examples/custom-labels.md)
- [Smooth width](https://hextaui.com/docs/button/examples/smooth-width.md)
- [Error details](https://hextaui.com/docs/button/examples/error-details.md)
- [Icon buttons](https://hextaui.com/docs/button/examples/icon-feedback.md)
- [Feedback on every variant](https://hextaui.com/docs/button/examples/variants-feedback.md)
- [Controlled loading](https://hextaui.com/docs/button/examples/controlled-loading.md)
- [Controlled status](https://hextaui.com/docs/button/examples/controlled-status.md)
- [As a link](https://hextaui.com/docs/button/examples/link.md)
- [Right to left](https://hextaui.com/docs/button/examples/rtl.md)
