I am looking for an extremely simple example of a basic working post response. The application only needs to have two routes/controllers.The first is the homepage that contains an HTML form, and the other is for the embedded forms post response.
Suprisingly all the examples of similar code online are completley bloated (IMHO) with code that I don't understand.
As it stands, the error I am getting is asking for a CSRF token(yes, I know what that is) . In some of the code I've viewed online the forms have a line that looks something like this to generate it:
<input type="hidden" name="csrf_token" value="<%= csrf_token(@conn) %>">
When I add the above line to my form I get an error that says the csrf_token() function is undefined.
So far here is what I have:
HTML
<form action="/create" method="post">
<input type="text" name="todo">
<input type="submit">
</form>
router
scope "/", ProjWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
post "/create", TodoController, :new
end
PageController
defmodule ProjWeb.PageController do
use ProjWeb, :controller
def index(conn, _params) do
render conn, "index.html"
end
end
TodoController
defmodule ProjWeb.TodoController do
use ProjWeb, :controller
def new(conn, _params) do
render conn, "index.html"
end
end
How do I make the post request work with the code I have so far ?
Thank you