# frozen_string_literal: true require "hanami/view" module Hanami module Helpers # Helper methods for generating HTML forms. # # These helpers will be automatically available in your view templates, part classes and scope # classes. # # This module provides one primary method: {#form_for}, yielding an HTML form builder. This # integrates with request params and template locals to populate the form with appropriate # values. # # @api public # @since 2.0.0 module FormHelper require_relative "form_helper/form_builder" # Default HTTP method for form # # @since 2.0.0 # @api private DEFAULT_METHOD = "POST" # Default charset # # @since 2.0.0 # @api private DEFAULT_CHARSET = "utf-8" # CSRF Token session key # # This name of this key is shared with the hanami and hanami-controller gems. # # @since 2.0.0 # @api private CSRF_TOKEN = :_csrf_token include Hanami::View::Helpers::TagHelper # Yields a form builder for constructing an HTML form and returns the resulting form string. # # See {FormHelper::FormBuilder} for the methods for building the form's fields. # # @overload form_for(base_name, url, values: _form_for_values, params: _form_for_params, **attributes) # Builds the form using the given base name for all fields. # # @param base_name [String] the base # @param url [String] the URL for submitting the form # @param values [Hash] values to be used for populating form field values; optional, # defaults to the template's locals or to a part's `{name => self}` # @param params [Hash] request param values to be used for populating form field values; # these are used in preference over the `values`; optional, defaults to the current # request's params # @param attributes [Hash] the HTML attributes for the form tag # @yieldparam [FormHelper::FormBuilder] f the form builder # # @overload form_for(url, values: _form_for_values, params: _form_for_params, **attributes) # @param url [String] the URL for submitting the form # @param values [Hash] values to be used for populating form field values; optional, # defaults to the template's locals or to a part's `{name => self}` # @param params [Hash] request param values to be used for populating form field values; # these are used in preference over the `values`; optional, defaults to the current # request's params # @param attributes [Hash] the HTML attributes for the form tag # @yieldparam [FormHelper::FormBuilder] f the form builder # # @return [String] the form HTML # # @see FormHelper # @see FormHelper::FormBuilder # # @example Basic usage # <%= form_for("book", "/books", class: "form-horizontal") do |f| %> #