jononomo
I have a form in my EEX file in my Phoenix project as follows:
<%= form_for @conn, Routes.user_path(@conn, :create), [as: :user], fn f -> %>
<div>
<%= label f, :email, class: 'sr-only' %>
<%= email_input f, :email, required: true %>
</div>
<div>
<%= label f, :password, class: 'sr-only' %>
<%= password_input f, :password, required: true %>
</div>
<%= submit "Log in" %>
<% end %>
This generates a form with a button as follows:
<button type="submit">Log in</button>
But I would like more control over what is inside the <button></button> tag – I would like to add a bunch of other HTML inside the button tag, including some SVG images.
<button type="submit">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"/>
</svg>
</button>
How can I add my own SVG tags inside the button tag while still using the Phoenix.HTML.Form module as a helper to generate the button.
Or does it just not make sense for me to use the <%= submit "Log in" %> shortcut for my case? Since I’m doing everything within the form_for function, I’d like to be consistent with the way I generate other form elements, and also make sure I have my form all tied together properly.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You can use
do/endblocks instead of string labels for many html functions:c4710n
As a supplyment, it’s better to manage svg image with some helpers. Or, it will interfere with your view.
jononomo
When I try this code:
I get the error
undefined function submit/3I guess that adding the
do...endis like adding a third argument. So I guesssubmit/2exists butsubmit/3does not?LostKobrakai
Skip the
"Log in". It can be either text or ado/endblock.jononomo
Currently I pass information to the submit form helper so that I can style the button by setting the class.
How can I set the class on the button if I jump directly into the do-end block?
Also, under what scenario do I gain a big advantage from using this
submithelper fromPhoenix.HTML.Form? It seems to me like it doesn’t really help much – it seems like different syntax for saying the same thing and I’m getting no magic lifting happening for me behind the scenes.l00ker
The button text (or other content) just gets placed inside the do-end block:
In this case
"Log In"could be replaced with your<svg />.Have a look at Phoenix.HTML.Tag.content_tag/2/3 to get a better understanding of how this works.
jononomo
Thanks!!
crockwave
In a Phoenix Liveview
leexfile, I reference anSVGin thebuttontag, then use CSS to style the button shape/color and the SVG attributes, such as position. Also, the button is disabled if the associated input field value is blank.Following is CSS that renders a round button with the SVG centered, and to the right side of the associated input assigned a
classvalue ofpost_send: