SproutCMS

This is the code documentation for the SproutCMS project

class Form

Helper functions for outputting form elements.

Wraps form fields (e.g. from Fb) with additional HTML.

Most wrapping will done using the __callStatic method which actually just calls Form::fieldAuto.
That method uses reflection to look for a custom docblock tag, @wrap-in-fieldset.
If that docblock tag is found, the field is wrapped in Form::fieldFieldset
If that docblock tag is not found (the most common case), the field is wrapped in Form::fieldPlain

If the field being wrapped isn't in the Fb helper, the methods fieldAuto, fieldPlain, and fieldFieldset
can be invoked directly.

The outermost wrapper DIV around the field has a class of "field-element".
Additional classes are also added:
 - The method and class name, in the format 'field-element--id-<name>'
 - If an "id" attribute is set, in the format 'field-element--id-<id>'
 - If the field is required, 'field-element--required'
 - If the field is disabled, 'field-element--disabled'
 - If the field has an error, 'field-element--error'
 - One or more custom classes can be specified using the attribute "-wrapper-class".
   Each (array or space separated) class is prefixed with 'field-element--'

Example

Form::setData($data);
Form::setErrors($errors);
 
Form::nextFieldDetails('First name', true);
echo Form::text('first_name');
 
Form::nextFieldDetails('Email', true, 'Please enter your email address');
echo Form::email('email', [], ['-wrapper-class' => 'small']);
 
Form::nextFieldDetails('Phone', false, 'Enter a phone number using the unique UI');
echo Form::fieldPlain('SproutModules\Someone\CustomModule\Helpers\FbHack::phone', 'phone', [], []);

Class structure