The Amilma Forms options
define the containers and various HTML elements your forms will use.
The Default options are for use with Bootstrap 5.
Each can be overwritten the way you want to match other framework
You can call the getOptions(mixed $opt)
function at any time to display the options and their values for debugging purposes.
The $opt
argument can be an option name, or an array of options names, or null if you want to show all the options keys => values.
For example, with Bootstrap, each group (label + element) has to be wrapped into a <div class="form-group"></div>
and to have a .form-control class
We also need do add .col-sm-x
& .control-label
to labels,
and to wrap elements with <div class="col-sm-x mb-3"></div>
.
The form options allow us to configure it all efficiently.
If needed, wrappers can contain two HTML elements.
It can be done with elementsWrapper, checkboxWrapper, and radioWrapper.
To add an input wrapper, see the addInputWrapper function.
$bs5_options = array(
'formHorizontalClass' => 'form-horizontal',
'formVerticalClass' => '',
'elementsWrapper' => '<div class="bs5-form-stacked-element mb-3"></div>',
'checkboxWrapper' => '<div class="form-check"></div>',
'radioWrapper' => '<div class="form-check"></div>',
'helperWrapper' => '<span class="form-text"></span>',
'buttonWrapper' => '<div class="mb-3"></div>',
'wrapElementsIntoLabels' => false,
'wrapCheckboxesIntoLabels' => false,
'wrapRadiobtnsIntoLabels' => false,
'elementsClass' => 'form-control',
'wrapperErrorClass' => '',
'elementsErrorClass' => 'is-invalid',
'textErrorClass' => 'invalid-feedback w-100 d-block',
'verticalLabelWrapper' => false,
'verticalLabelClass' => 'form-label',
'verticalCheckboxLabelClass' => 'form-label',
'verticalRadioLabelClass' => 'form-label',
'horizontalLabelWrapper' => false,
'horizontalLabelClass' => 'col-form-label',
'horizontalLabelCol' => 'col-sm-4',
'horizontalOffsetCol' => 'col-sm-offset-4 mb-3',
'horizontalElementCol' => 'col-sm-8 mb-3',
'inlineCheckboxLabelClass' => 'form-check-label',
'inlineRadioLabelClass' => 'form-check-label',
'inlineCheckboxWrapper' => '<div class="form-check form-check-inline"></div>',
'inlineRadioWrapper' => '<div class="form-check form-check-inline"></div>',
'iconBeforeWrapper' => '<div class="input-group-text"></div>',
'iconAfterWrapper' => '<div class="input-group-text"></div>',
'btnGroupClass' => 'btn-group',
'requiredMark' => '<sup class="text-danger">* </sup>',
'openDomReady' => 'document.addEventListener(\'DOMContentLoaded\', function(event) {',
'closeDomReady' => '});'
);
The table below shows the correspondence between the options and the generated HTML code. The values of the options are arbitrary, used simply to illustrate the examples.
formHorizontalClass | <form class=" |
---|---|
formVerticalClass | <form class=" |
elementsWrapper |
|
checkboxWrapper |
|
radioWrapper |
|
helperWrapper |
|
buttonWrapper |
|
wrapElementsIntoLabels (if true) |
|
wrapCheckboxesIntoLabels (if true) |
|
wrapRadiobtnsIntoLabels (if true) |
|
elementsClass | <input class=" |
wrapperErrorClass | <div class="[form-group] |
elementsErrorClass | <input class="[form-control] |
textErrorClass | <p class=" |
verticalLabelWrapper | if true, the labels will be wrapped in a <div class=" |
verticalLabelClass | <div class=" |
verticalCheckboxLabelClass | <label for="[fieldname]" class=" |
verticalRadioLabelClass | <label for="[fieldname]" class=" |
horizontalLabelWrapper | if true, the labels will be wrapped in a div with the column class instead of having the column class themselves |
horizontalLabelClass, | <label class=" |
horizontalOffsetCol | // when label is empty, automaticaly offsetting field container |
horizontalElementCol | <div class=" |
inlineCheckboxLabelClass | <label class=" |
inlineRadioLabelClass | <label class=" |
inlineCheckboxWrapper |
|
inlineRadioWrapper |
|
iconBeforeWrapper | <div class=" |
iconAfterWrapper | <div class=" |
btnGroupClass | <div class=" |
requiredMark | // required markup is automaticaly added on required fields |
openDomReady |
|
closeDomReady |
|
You can use Amilma Forms with any framework, e.g., Semantic-UI, Pure, Skeleton, UIKit, Milligram, Susy, Bulma, Kube, etc.
You simply have to change the options to match your framework HTML & CSS classes:
$options = array(
// your options here
);
$form->setOptions($options);
If you always use the same framework, the best way is to create a custom function with your custom config in the FormExtended
class.