Components
Forms (v1)
Forms (v1)
This page is for users using the old form structure (pre Phoenix 1.7).
v1 way (pre Phoenix 1.7):
<.form :let={f} as={:user} for={@changeset} phx-submit="on_submit">
<.form_field type="text_input" form={f} field={:your_field} />
<.form_field
form={f}
field={:a_select_field}
type="select"
options={[{"Option 1", "1"}, {"Option 2", "2"}]}
/>
<.button type="submit" label="Submit" />
</.form>
v2 way (Phoenix 1.7):
<.form for={@form} phx-submit="on_submit">
<.field field={@form[:email]} />
<.field
field={@form[:email]}
type="select"
options={[{"Option 1", "1"}, {"Option 2", "2"}]}
/>
<.button type="submit" label="Submit" />
</.form>
There are two ways of creating form fields
- All inclusive option: Use `.form_field', which includes the input label and any errors on the changeset. Use this if you just want a good looking form that works with errors out of the box.
- Explicit option: Individually write out the label, input and errors. Do this when you want to be more explicit option on where the label or errors go.