module Amber::Controller::Helpers::FormHelpers

Direct including types

Defined in:

amber/controller/helpers/form_helpers.cr

Instance Method Summary

Instance Method Detail

def checkbox(name : String, checked : Bool = false, **attrs) : String #

Generates a checkbox input field.

checkbox("remember_me")          # => "<input type=\"checkbox\" name=\"remember_me\" id=\"remember_me\" />"
checkbox("terms", checked: true) # => "<input type=\"checkbox\" name=\"terms\" id=\"terms\" checked />"

[View source]
def email_field(name : String, value : String | Nil = nil, **attrs) : String #

Generates an email input field.


[View source]
def form_for(action : String, method : String = "POST", **attrs, &block : -> String) : String #

Generates an HTML form tag with automatic CSRF token inclusion. For non-GET/POST methods, a hidden _method field is emitted.

form_for("/users", method: "POST") { "<input />" }

[View source]
def hidden_field(name : String, value : String) : String #

Generates a hidden input field.


[View source]
def label(for_field : String, text : String | Nil = nil, **attrs) : String #

Generates a label element.

label("email")                     # => "<label for=\"email\">Email</label>"
label("email", text: "Your Email") # => "<label for=\"email\">Your Email</label>"

[View source]
def number_field(name : String, value : Number | Nil = nil, **attrs) : String #

Generates a number input field.


[View source]
def password_field(name : String, **attrs) : String #

Generates a password input field. Never includes a value attribute.


[View source]
def radio_button(name : String, value : String, checked : Bool = false, **attrs) : String #

Generates a radio button input field.

radio_button("color", "red")                 # => "<input type=\"radio\" name=\"color\" id=\"color_red\" value=\"red\" />"
radio_button("color", "blue", checked: true) # => "<input type=\"radio\" name=\"color\" id=\"color_blue\" value=\"blue\" checked />"

[View source]
def select_field(name : String, options : Array, selected : String | Nil = nil, **attrs) : String #

Generates a select dropdown field.

select_field("color", [{"Red", "red"}, {"Blue", "blue"}], selected: "blue")
select_field("size", ["Small", "Medium", "Large"])

[View source]
def submit_button(text : String = "Submit", **attrs) : String #

Generates a submit button.

submit_button                     # => "<input type=\"submit\" value=\"Submit\" />"
submit_button("Save")             # => "<input type=\"submit\" value=\"Save\" />"
submit_button("Go", class: "btn") # => "<input type=\"submit\" value=\"Go\" class=\"btn\" />"

[View source]
def text_area(name : String, value : String | Nil = nil, **attrs) : String #

Generates a textarea element.

text_area("bio")                 # => "<textarea name=\"bio\" id=\"bio\"></textarea>"
text_area("bio", value: "Hello") # => "<textarea name=\"bio\" id=\"bio\">Hello</textarea>"

[View source]
def text_field(name : String, value : String | Nil = nil, **attrs) : String #

Generates a text input field.

text_field("name")                        # => "<input type=\"text\" name=\"name\" id=\"name\" />"
text_field("name", value: "John")         # => "<input type=\"text\" name=\"name\" id=\"name\" value=\"John\" />"
text_field("name", class: "form-control") # => "<input type=\"text\" name=\"name\" id=\"name\" class=\"form-control\" />"

[View source]