diff --git a/lib/keila/contacts/schemas/form_settings.ex b/lib/keila/contacts/schemas/form_settings.ex index 1bb994c6..53379252 100644 --- a/lib/keila/contacts/schemas/form_settings.ex +++ b/lib/keila/contacts/schemas/form_settings.ex @@ -22,6 +22,7 @@ defmodule Keila.Contacts.Form.Settings do field(:input_border_color, :string, default: "#6b7280") field(:input_text_color, :string, default: "#111827") field(:success_text, :string) + field(:success_url, :string) end def changeset(struct \\ %__MODULE__{}, params) do @@ -43,7 +44,8 @@ defmodule Keila.Contacts.Form.Settings do :submit_label, :submit_bg_color, :submit_text_color, - :success_text + :success_text, + :success_url ]) end end diff --git a/lib/keila_web/controllers/public_form_controller.ex b/lib/keila_web/controllers/public_form_controller.ex index f81f6e88..a1b6c0c3 100644 --- a/lib/keila_web/controllers/public_form_controller.ex +++ b/lib/keila_web/controllers/public_form_controller.ex @@ -33,7 +33,8 @@ defmodule KeilaWeb.PublicFormController do {:ok, contact = %Contact{}} -> data = if form.settings.captcha_required, do: %{"captcha" => true}, else: %{} Tracking.log_event("subscribe", contact.id, data) - render(conn, "success.html") + + render_success_or_redirect(conn) {:ok, form_params = %FormParams{}} -> conn @@ -82,7 +83,7 @@ defmodule KeilaWeb.PublicFormController do Tracking.log_event("subscribe", id, data) Contacts.delete_form_params(form_params.id) - render(conn, "success.html") + render_success_or_redirect(conn) {:ok, form_params = %FormParams{}} -> conn @@ -94,6 +95,13 @@ defmodule KeilaWeb.PublicFormController do end end + defp render_success_or_redirect(conn) do + case conn.assigns.form.settings.success_url do + url when url not in [nil, ""] -> redirect(conn, external: url) + _other -> render(conn, "success.html") + end + end + def cancel_double_opt_in(conn, %{"hmac" => hmac}) do form = conn.assigns.form form_params = conn.assigns.form_params diff --git a/lib/keila_web/templates/form/edit_live.html.heex b/lib/keila_web/templates/form/edit_live.html.heex index b2a41245..6993627e 100644 --- a/lib/keila_web/templates/form/edit_live.html.heex +++ b/lib/keila_web/templates/form/edit_live.html.heex @@ -107,6 +107,12 @@ <%= text_input(fs, :success_text, class: "text-black") %> <% end %> +