Repository navigation
v0.2.0
Multi-value fields, strict option checking, file uploads, layout, new inputs and custom field
types. Read "Upgrading from 0.1" in the README before upgrading.
Added
- Multi-value fields:
select()->multiple()(withsize()) and a newcheckboxes()group
field. Both submit asname[]andvalidated()returns a list, empty when nothing is
chosen. eachRules()for rules checked against every item of a multi-value field, using
CodeIgniter'sname.*wildcard.permit_emptyis added automatically so an empty list
passes; userules('required')to require at least one item.- New
field_checkboxesview; views receive$inputName,$valuesand$multiple. - Strict option checking: submitted values for selects, multi-selects, radios, checkbox
groups and single checkboxes must be among the field's options (for a checkbox, its checked
value). Controlled by$strictOptionsand$strictOptionsMessagein config, per field with
->strictOptions(bool)and->messages(['options' => '...']). Errors survive
redirect()->withInput(). Contracts\ChoiceFieldInterface(getAllowedValues(),getStrictOptions()) for custom
fields with a fixed set of values;Form::usesStrictOptions().- File uploads:
file()field withrequired(),multiple(),maxSize()(kilobytes),
extensions(),mimes(),image()andmaxDimensions(), mapped to CodeIgniter's file
rules, plus a generatedacceptattribute. Optional file fields are only validated when a
file is uploaded. Uploads are never part ofvalidated(); get them with
Form::getFile(),Form::getFiles()andForm::hasUploadedFile(). - Forms with a file field are sent as multipart automatically.
- After a failed submission, file fields show a "choose the file again" hint
($fileReselectMessage, theme classreselect), since browsers cannot refill them. Contracts\FileFieldInterfacefor custom upload fields; newfield_fileview.- Theme templates missing from a theme's views folder fall back to the package's bundled copy
of that theme, so views published before an upgrade keep working with new field types.
php spark forms:publishadds the missing templates without touching customised ones. - Layout:
row()places fields side by side andfieldset()groups them under a titled
section (description(),id()); both nest and takeaddClass(). Fields and fieldsets get
width(1-12)for their column inside a row; fields without a width share the row. Layout is
defined in the form class and rendered by<?= $form ?>andfields(); fields themselves
stay a flat list, so values, validation andfield()are unaffected. Form::getLayout(),Layout\Row,Layout\Fieldset; newlayout_rowand
layout_fieldsetviews and theme classesrow,column({width}placeholder),
column_auto,section,section_legend,section_description.- New inputs:
time(),datetimeLocal(),color()(values lower-cased) andsearch().
date(),time()anddatetimeLocal()sharemin(),max()andstep()through the new
Fields\DateTimeInputFieldbase class. - Custom field type registry:
$fieldTypes = ['money' => MoneyField::class]in config makes
$this->money('price')a builder method, including inline chaining and inside groups.
Registrations are checked: camelCase names, no clashes with built-in types orForm
methods, and classes must implementFieldInterface. Form::addField($type, $name, $label)creates any built-in or registered field by type key;
Form::hasFieldType();Support\FieldTypes::BUILT_INlists the built-in keys.- Custom fields can render their own view: a
VIEWcontaining a path (fields/moneyor
Vendor\Package\Views\money) is loaded as given instead of from the theme. Field views can
ask$class()for any theme class key.
Changed
- Behaviour change: strict option checking is on by default. A form that accepted values
outside a field's options in 0.1 now rejects them. Set$strictOptions = falsein
app/Config/Forms.phpto restore the 0.1 behaviour, or opt single fields out with
->strictOptions(false). Existingin_listrules keep working; they are now optional for
option fields. FieldInterfacehas three new methods:getEachRules(),isMultiple()andgetWidth(). Custom fields
extendingFields\Fieldget both automatically; classes implementing the interface
directly must add them.getOptionId()moved fromRadiointo the sharedHasOptionstrait.fields()with no arguments now renders the form's layout (rows and fieldsets) instead of
a flat list.fields('a', 'b')with names is unchanged. Publishedform.phpviews get
layouts automatically.- The
field_selectview uses$inputNameand$values. Re-publish the views
(php spark forms:publish --force) or apply the same change if you customised it.
Fixed
- An array posted to a single-value field (for example
nickname[]=x) could pass validation
on fields without rules and reachvalidated()as an array. Single-value fields now treat
a posted array as no value, and an unticked checkbox's array counts as unticked.