====== Forms ====== Rack provides a set of classes enable form handling and rendering in ''include/form.php''. This page discusses the public form API. ===== Form class ===== The core of Rack's form system is the ''%%Form%%'' class. All interactions with a form and it's fields should happen through this class, or one of its subclasses. ==== Initialization ==== The constructor of the form class takes two arguments, the form's name (which is an id-like string) and a lists of fields. The latter may be left out, as fields can be added through the ''%%add_field($field_name, $field)%%'' and ''%%add_fields($fields)%%'' functions. If the form has been submitted, the fields will automatically be filled with the submitted data once they're added to the form. If needed, this process can be manually executed by calling the function ''%%initizize()%%'' on the form object. Sometimes, it may be desirable to populate the fields with default data. This can be done through the ''%% populate_field($field_name, $values)%%'' and ''%%populate_fields($values)%%'' functions, which set the values of the fields without overwriting submitted data. ==== Validation ==== Forms can be validated through their ''%%validate()%%'' function, which will return ''%%true%%'' if the form has been submitted and all fields have valid input and will return ''%%false%%'' otherwise. When custom validation is needed, this should generally be done by subclassing the ''%%Form%%'' class and overriding its ''%%validate()%%'' function. In some specific cases, it may be more desirable to subclass a single ''%%Field%%'' class and override its ''%%validate()%%'' function instead. ==== Rendering ==== There are tree main rendering strategies supported. Automatic rendering, semi-automatic rendering and manual rendering. Automatic rendering can be done calling the function ''%%render($action=null, array $attributes=[])%%'', which allows for customizing the arguments of the ''