zervis

zervis

Form_for not working in Phoenix 1.7

Hi there,

I have problem following this tutorial in Phoenix 1.7 (Create an index page):

mix phx.server
Compiling 1 file (.ex)
warning: undefined function submit/1 (expected VamosWeb.EventsHTML to define such a function or for it to be imported, but none are available)
  lib/todo_web/controllers/items_html/index.html.heex:15

warning: undefined function date_input/2 (expected VamosWeb.EventsHTML to define such a function or for it to be imported, but none are available)
  lib/todo_web/controllers/items_html/index.html.heex:12

warning: undefined function text_input/2 (expected VamosWeb.EventsHTML to define such a function or for it to be imported, but none are available)
  lib/todo_web/controllers/items_html/index.html.heex:9

warning: undefined function text_input/2 (expected VamosWeb.EventsHTML to define such a function or for it to be imported, but none are available)
  lib/todo_web/controllers/items_html/index.html.heex:6


== Compilation error in file lib/todo_web/controllers/items_html.ex ==
** (CompileError) lib/todo_web/controllers/items_html/index.html.heex:3: undefined function form_for/3 (expected VamosWeb.EventsHTML to define such a function or for it to be imported, but none are available)

My form:

<h1>Events</h1>

<%= form_for @changeset, Routes.events_path(@conn, :create), fn f -> %>

  <label>
    Add a new todo item: <%= text_input f, :title %>
  </label>
  <label>
    Add a new todo item: <%= text_input f, :description %>
  </label>
  <label>
    Add a new todo item: <%= date_input f, :date %>
  </label>

  <%= submit "Submit" %>
<% end %>

<%= for item<- @items do %>
  <h3><%= item.description %></h3>

  <%= if event.completed do %>
    <p style="color:green;">Completed</p>
  <% else %>
    <p style="color:red;">To be done </p>
  <% end %>

  <hr>
<% end %>

My items_html.ex:

defmodule TodoWeb.ItemsHTML do
  use TodoWeb, :html

  embed_templates "items_html/*"
end

Any clue what I’m doing wrong?

Marked As Solved

josevalim

josevalim

Creator of Elixir

Phoenix v1.7 no longer imports Phoenix.HTML.Form but you can bring it back by adding import Phoenix.HTML.Form in your def html and/or def component.

Also Liked

josevalim

josevalim

Creator of Elixir

With HEEx, it is more natural to build the components yourself with HTML, rather than hiding everything behind functions.

See how CoreComponents handles forms. :slight_smile:

sodapopcan

sodapopcan

My guess is to encourage using the tidier <.form> function component instead.

kokolegorille

kokolegorille

Also judging by the date of the blog post, it is more likely to be Phoenix 1.6 :slight_smile:

Where Next?

Popular in Questions Top

mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement