Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Displaying validation errors in our forms

As of yet, we haven't actually hooked up any of this new shiny logic in our form, so if we try to submit anything we'll just see a generic error message that isn't very helpful. One thing that we left out of each of our forms is a per-field error message. Phoenix will helpfully wrap any errors inside of a span with a help-block class, so first let's open up assets/css/app.css and add the following code:

span.help-block {  color: #f00;}

Next, we'll jump into our users form and start adding error_tag statements to each of our fields. Open up lib/vocial_web/templates/user/form.html.eex and follow along with each field update as follows:

  • Username:
<%= label f, :username, "Username:" %><br /><%= text_input ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content