# Your first form

> A sign-up form with two inputs and a submit handler, and no plugins.

Source: https://forms.lunarhue.dev/solid/basics/first-form

This is the form you'll end up with. Fill it in and submit it.

```tsx title="sign-up.tsx"
import { createForm, createForms, inputProps } from "@lunarhue/forms-solid";
import { Show } from "solid-js";

// No plugins and no field components: this form uses only what every form has.
const forms = createForms();

const signUp = forms.define({
  defaultValues: { name: "", email: "" },
  onSubmit: (value) => `Signed up ${value.name}.`,
});

export default function SignUpForm() {
  const form = createForm(signUp, { id: "sign-up" });
  return (
    <form.Form>
      {(formProps) => (
        <form {...formProps}>
          <form.Field name="name">
            {(field) => (
              <label>
                Name
                <input {...inputProps(field)} />
              </label>
            )}
          </form.Field>
          <form.Field name="email">
            {(field) => (
              <label>
                Email
                <input {...inputProps(field, { type: "email" })} />
              </label>
            )}
          </form.Field>
          <button type="submit">Sign up</button>
          <p role="status">
            <Show when={form.state.submission.status === "succeeded" && form.state.submission}>
              {(submission) => submission().result}
            </Show>
          </p>
        </form>
      )}
    </form.Form>
  );
}
```

Every page in Basics uses the adapter alone. No plugins, nothing registered.

```bash
npm install @lunarhue/forms-solid
```

## Make a forms object

`createForms` holds what your forms share: plugins, field components and
settings. This form needs none of them.

```ts title="sign-up.tsx"
import { createForms } from "@lunarhue/forms-solid";

const forms = createForms();
```

## Define the form

```ts title="sign-up.tsx"
const signUp = forms.define({
  defaultValues: { name: "", email: "" },
  onSubmit: (value) => `Signed up ${value.name}.`,
});
```

`defaultValues` is the value the form starts from, and its type is the form's
type. Here that is `{ name: string; email: string }`. `onSubmit` gets a copy
of the value when the user submits.

## Render it

`createForm` makes a form from the definition for this component.

```tsx title="sign-up.tsx"
import { createForm, inputProps } from "@lunarhue/forms-solid";

export default function SignUpForm() {
  const form = createForm(signUp);
  return (
    <form.Form>
      {(formProps) => (
        <form {...formProps}>
          <form.Field name="name">
            {(field) => (
              <label>
                Name
                <input {...inputProps(field)} />
              </label>
            )}
          </form.Field>
          <form.Field name="email">
            {(field) => (
              <label>
                Email
                <input {...inputProps(field, { type: "email" })} />
              </label>
            )}
          </form.Field>
          <button type="submit">Sign up</button>
        </form>
      )}
    </form.Form>
  );
}
```

- `form.Form` hands your `<form>` its submit handler as `formProps`, and turns
  off the browser's own validation.
- `form.Field` takes a field name and passes that field to its child. The
  compiler checks the name, so `name="emial"` is a type error.
- `inputProps(field)` gives the input its value, `name`, `id`, the change and
  blur handlers, and the aria attributes for errors.

## Show the result

Whatever `onSubmit` returns becomes `submission.result`. Read it from the
form's state:

```tsx
<p role="status">
  <Show when={form.state.submission.status === "succeeded" && form.state.submission}>
    {(submission) => submission().result}
  </Show>
</p>
```

`form.state` is reactive, so only this text updates.

A submission is `idle`, `submitting`, `invalid`, `failed` or `succeeded`. If
`onSubmit` throws, the status is `failed` and `error` holds what it threw.
[Submit](https://forms.lunarhue.dev/solid/basics/submit.md) has the rest.

## Next

The form takes anything right now. [Validation](https://forms.lunarhue.dev/solid/basics/validation.md) adds the checks.
