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.

Last Post!

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

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
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
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
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
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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

We're in Beta

About us Mission Statement