Form

Defines a form that lets the user submit information


Provides a wrapper for Phoenix.HTML.Form.form_for/3. Additionally, adds the form instance that is returned by form_for/3 into the context, making it available to any child input.

All options passed via opts will be sent to form_for/3, for and action can be set directly and will override anything in opts.


@user = {
  "email": "",
  "name": ""
}
      
<Form for={%{}} as={:user} change="change" opts={autocomplete: "off"}>
  <Field name="name">
    <Label/>
    <div class="control">
      <TextInput value={@user["name"]}/>
    </div>
  </Field>
  <Field name="email" class="field">
    <Label>E-mail</Label>
    <div class="control">
      <TextInput value={@user["email"]}/>
    </div>
  </Field>
</Form>

<pre>@user = {Jason.encode!(@user, pretty: true)}</pre>
    

# Public API

Name Description Type Values Default
id The ID of the form attribute. If an ID is given, all form inputs will also be prefixed by the given ID. Required to enable form recovery following crashes or disconnects.

:string
for Required. Atom or changeset to inform the form data.

:any
action URL to where the form is submitted.

:string "#"
as The server side parameter in which all parameters will be gathered.

:atom
method Method to be used when submitting the form.

:string
multipart When true, sets enctype to "multipart/form-data". Required when uploading files.

:boolean false
csrf_token For "post" requests, the form tag will automatically include an input tag with name _csrf_token. When set to false, this is disabled.

:any
trigger_action Trigger a standard form submit on DOM patch to the URL specified in the form's standard action attribute. This is useful to perform pre-final validation of a LiveView form submit before posting to a controller route for operations that require Plug session mutation.

:boolean
errors Keyword list of errors for the form.

:keyword
opts Keyword list with options to be passed down to Phoenix.HTML.Tag.tag/2.

:keyword []
class Class or classes to apply to the form.

:css_class