Sidi_Mohammed

Sidi_Mohammed

Need some help with basic form submissions

Hello,
as RESTful API from resources offers new and create routes to create a new user, I don’t know how to use them,
new will trigger the server to return an HTML form to upload our informations, okay that’s fine, but how we can send those informations back to the server ? and what is the relation with create route ?

Marked As Solved

codeanpeace

codeanpeace

GET /users/new HelloWeb.UserController :new

POST /users HelloWeb.UserController :create

source: Routing — Phoenix v1.8.8

The :new route is to get the blank form, hence the GET HTTP request. While the :create route is to submit/post the completed form, hence the POST HTTP request.

If you’re on a relatively new version of Phoenix and ran mix phx.gen.html ..., you’d see a form component with an action that points to a :create route.

<.form :let={f} for={@changeset} action={Routes.comment_path(:create, @comment)}> # or action={~p"/comments"} if using verified routes
  <.input field={f[:body]} />
</.form>

Also Liked

codeanpeace

codeanpeace

Phoenix supports both traditional stateless RESTful HTTP request/response through Phoenix.Controller as well as stateful WebSocket connections through LiveView Phoenix.Liveview.

If I’m understanding you correctly, you can just scroll up using the link above for an example of using the form component within a LiveView or alternatively use this link. You can also use the mix phx.gen.live task to generate functional LiveView example code.

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
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
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement