PhoenixIntegration.Requests.fetch_form

You're seeing just the function fetch_form, go back to PhoenixIntegration.Requests module for more information.
Link to this function

fetch_form(conn, opts \\ %{})

View Source

Convenience function to find and return a form in a conn.resp_body.

Returns the form as a map.

Parameters

  • conn should be a conn returned from a previous request that rendered some html. The functions are designed to pass the conn from one call into the next via pipes.
  • opts A map of additional options
    • identifier indicates which link to find in the html. Defaults to nil. Valid values can be in the following forms:
      • "/some/path" specify the link's href starting with a "/" character
      • "http://www.example.com/some/uri", specify the href as full uri starting with either "http" or "https"
      • "#element-id" specify the html element id of the link you are looking for. Must start start with the "#" character (same as css id specifier).
      • "Some Text" specify text contained within the link you are looking for.
    • :method - restricts the forms searched to those whose action uses the given method (such as "post" or "put"). Defaults to nil;
    • :finder - finding string passed to Floki.find. Defaults to "form"

If no opts.identifier is specified, the first form that makes sense is used. Unless you have multiple forms on your page, this often is the most understandable pattern.

If no appropriate form is found, fetch_form raises an error.

If you have more than one form in the response, you will probably need to use the identifier options similar to what how you specify a form for submit_form or follow_form.

Example:

  # get the value from a form on the page.
  fetch_form( conn )

  ## returns something like...
  %{
    id:     "some_id",
    method: "put",
    action: "/some/action"
    inputs: %{
      user: %{
        first_name: "Jane",
        last_name:  "Doe"
      }
    }
  }

Note: this fetches the form as it is in the response. It will not show you updates you are making as you prepare for the next submission.

In HTML, tags without values are not sent to the controller. For your convenience, this function shows you that valueless tags are in the form, marking them with :no_value. Note that some tags have values even if there's no value or checked attribute. For example, a text input's default value is the empty string.