mistralys / html_quickform2
Provides methods to create, validate and render HTML forms in PHP.
Installs: 37 538
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 18
Open Issues: 6
Requires
- php: >=7.4
- symfony/polyfill-php80: >=v1.27.0
Requires (Dev)
- phpstan/phpstan: >=1.10
- phpunit/phpunit: >=9.6
README
This fork focuses on code modernization, performance and quality of life improvements.
Requirements
- PHP 7.4+ (PHP8 compatible)
- Composer
Installation
Add as dependency to your composer.json
file with:
composer require mistralys/html_quickform2
Also see the Packagist page.
Additions and improvements
- Chainable element methods as alternative to attribute arrays.
- Element factory class for easy element creation.
- Better code completion support through typed return values.
- Ongoing overall code modernization with strict typing.
- Quality of life improvements overall.
- Removed dependencies on PEAR packages.
Some changes in detail:
- Elements:
set/getRuntimeProperty()
method to store data at runtime - Default array datasource:
setValues()
method - Textarea element:
setRows()
/setColumns()
methods - Elements:
makeOptional()
method to remove any required rules - Elements:
hasErrors()
method to check if an element has errors after validation - Elements:
getRules()
method to retrieve all rules added to the element - Elements:
hasRules()
method to check if an element has any rules - Elements:
addRuleXXX()
shorthand methods, includingaddRuleRequired()
. - Elements:
appendComment()
method to append text to an existing comment. - Elements:
setComment()
extended to allowStringable
values. - Elements:
isFrozen()
method to check if an element is frozen. - Containers:
requireElementById()
with non-null return value. - Text-based elements:
addFilterTrim()
method. - Select element:
prependOption()
method to insert an element at the top. - Select element: Support for selects with a custom OptGroup class.
- Select element: OptGroups
getLabel()
method. - Select element:
countOptions()
method with recursive capability. - Select Element: Added
makeMultiple()
andisMultiple()
. - Select Element: Added
setSize()
andgetSize()
. - Select Element: Added
getSelectedOption()
. - Date element: Setter and getter methods for options.
- Input elements: Added
setLabel()
method where relevant. - Checkbox element: Added
setChecked()
method. - Image element: Added
setURL()
method. - Button Element: Added
makeSubmit()
andmakeButton()
. - Form: Added
getMethod()
. - Form: Added
makeMultiPart()
andisMultiPart()
. - Rules: The callback rule now has a method
getCallback()
to retrieve the configured callback. - Rules: Added static
setDefaultMessage()
to the required rule. - Renderers: Added setters and getters for renderer options.
- Renderers: Added specialized proxy classes to assist with IDE code completion.
- Renderers: Added proxy factory methods like
createArray()
andcreateCallback()
. - Renderers: Added a Bootstrap5 renderer.
Performance tweaks
- Container
getElementById()
method. - Auto-generated element IDs.
Element ID generation
The element ID generation mechanism has been modified, so it is no longer possible to rely on a specific naming scheme to predict the automatic element IDs. In practice, this was impractical at best anyway, and the new system has big performance gains.
Documentation
See the main branch for details and documentation: https://github.com/pear/HTML_QuickForm2
Additional documentation is available in the docs/knowledgebase folder, in the form of Markdown files.