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
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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #podcasts
- #code-sync
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








