Working with forms
Superform was built with the understanding that web applications have many different types of forms dependung on context and the user.
For example, a customer service user interface might have a more dense user interface with detailed error messages, signup forms on the marketing website might have a simpler layout with fewer fields, and the forms within the application UI might be somewhere in the middle.
Extending a Superform
Letβs start by creating a MarketingForm
form that extends the ApplicationForm
class that we can use in a βcontact salesβ and βsignupβ pages.
π Unlock content
Pre-order this course to unlock this video, source code, and content.
class MarketingForm < βββββββββββββββ
def βββ(βββββ)
βββ(class: "my-4") do
ββββββ βββββββββ.βββββ.βββββ(style: "font-bold")
ββββββ βββββββββ
end
end
def ββββββ(ββββ)
ββββββ(text: ββββ, class: "btn btn-primary btn-lg") do
ββββ
end
end
end
Rendering form blocks
βββββ ββ ββββββ ββ ββββ ββββ βββββββββββββ βββ βββββ βββββ ββββββ β βββ ββββ ββββββββ βββ ββββββ βββ
<%= ββββββ βββββββββββββ.βββ βββββ do |ββββ| %>
<%= ββββββ ββββ.βββ ββββ.βββββ(:email).βββββ(type: :email) %>
<%= ββββββ ββββ.βββ ββββ.βββββ(:name).βββββ %>
<%= ββββββ ββββ.βββ ββββ.βββββ(:phone).βββββ(type: :tel) %>
<%= ββββββ ββββ.ββββββ "Submit" %>
<% end %>
Rendering form classes
ββ βββ βββββββ βββ ββββ βββ ββ βββββββββββ ββ βββββ βββ ββββββββ ββββ βββ βββ βββββ
ββββββ βββ ββββ ββ ββββββ
class SalesForm < βββββββββββββ
def βββββββββββββ
βββ βββββ(:email).βββββ(type: :email)
βββ βββββ(:name).βββββ
βββ βββββ(:phone).βββββ(type: :tel)
ββββββ("Submit")
end
end
βββββ ββββ ββββ βββ βββ ββββββ ββ ββββ βββββ
<%= render SalesForm.new @user %>
ββββ ββββββββ βββββ ββ ββββββββ ββ ββββββ βββ ββββ ββββ ββ βββββββββ βββββββ