I am adjusting the user_registration_live.ex
generated by phx.gen.auth --live
to include a couple of extra fields.
Neither of them is nested; they are just placed right above and below the inputs for email and password in the simple_form
component:
<.input
field={@form[:preferred_role]}
type="text"
name="preferred_role"
label="Primary role"
value={"#{if not is_nil(@params.role), do: String.capitalize(@params.role)}"}
required
/>
<.input field={@form[:email]} type="email" label="Email" required />
<.input field={@form[:password]} type="password" label="Password" required />
<.input
field={@form[:accept_terms]}
type="checkbox"
label="I accept the Terms and Conditions"
required
/>
In the debug output of HANDLE EVENT "save"
when I submit the form, I can see that one of those fields ends up in the “user” map, while the other one in the parameters, i.e. at the same level as _csrf_token
:
[debug] Replied in 8ms
[debug] HANDLE EVENT "save" in LoginflowWeb.UserRegistrationLive
Parameters: %{"_csrf_token" => "e1MFPD9SWR0wDXlPDnYvHgQ4N1UjODN2-jLEq4nWcu5xD4cgguVdDhy5", "preferred_role" => "Supplier", "user" => %{"accept_terms" => "true", "email" => "user@example.com", "password" => "[FILTERED]"}}
[debug] Replied in 3ms
What determines this very weird behavior?