pinkcrab / form_fields
A simple form field creator ideal for wp-admin hook calls where a simple input is needed only as html.
Requires
- php: >=7.1.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: *
- gin0115/wpunit-helpers: dev-main
- object-calisthenics/phpcs-calisthenics-rules: *
- php-stubs/wordpress-stubs: ^5.6.0
- phpstan/phpstan: ^0.12.6
- phpunit/phpunit: ^7.0
- phpunit/phpunit-dom-assertions: ~2
- symfony/css-selector: 4.4.*
- symfony/dom-crawler: 4.4.*
- symfony/var-dumper: 4.*
- szepeviktor/phpstan-wordpress: ^0.7.2
- wp-coding-standards/wpcs: *
- yoast/phpunit-polyfills: ^0.2.0
- dev-master
- 0.2.0-beta1
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-develop
- dev-feature/gh38-auto-show-label
- dev-feature/add-missing-tests
- dev-feature/remove-wp-unit
- dev-feature/create-datalist-trait
- dev-feature/create-missing-fields
- dev-feature/gh-21-add-tel-field
- dev-feature/create-global-populate-attributes-based-on-traits
- dev-feature/gh-22-add-time-field
- dev-feature/gh23-week-input
- dev-feature/create-base-input-type-for-all-input-types
- dev-feature/gh15-add-colour-input
- dev-feature/use-keys-in-checkboxes
This package is auto-updated.
Last update: 2024-11-08 05:59:47 UTC
README
A simple way of parsing html5 form elements. Not a comprensive package, just enough to render most fields in wp-admin.
Installation
To install from composer please run
composer require pinkcrab/form_fields
Basic Usage
To create a simple form field and render(print) it to the screen
Input_Text::create( 'my_input' ) ->current( get_option( 'my_option', 'fallback' ) ) ->render();
You can return the HTML string of the input using as_string()
Input_Text::create( 'my_input' ) ->current( MyData::getOption( 'my_option', 'fallback' ) ) ->as_string();
Field Types
- Text
- Search
- Password
- URL
- Tel
- Number
- Range
- Text Area
- Date
- Date Time
- Checkbox (Single & Group)
- Radio
- Select
- Raw HTML
- Hidden
- Week
- Month
- Image (button)
- Submit
All inputs are extended from the Abstract_Field class and have all the functionality laid out in the Base Field section.
Labels
Output
Each form field is preloaded with a parser which can either render the input field or return the HTML. If you create your own field, you can make use of our existing parsers or create your own, using the Parser interface.
Input_Text::create('test')->render() // Prints the input Input_Text::create('test')->as_string() // Returns as HTML string.
Field Creation
All of our Form Fields has protected __construct
'ors and need to be created using the create() named constructor.
Input_Text::create('name')->render(); Input_Email::create('email')->render(); Input_Password::create('password')->render();
Version
Release 0.1.7
Change Log
- 0.1.8 - Label is now auto shown if length is above 0 and hidden if 0.
- 0.1.7 - Added in missing URL field, also all tests cleaned up and all attributes are now just controlled by attributes, not custom properties. Added in the Datalist attribute to all valid input fields. Tests extended running over 1500 assertions
- 0.1.6 - Added in missing fields [ Colour(inc alias Color), Week, Time, Month, File, Image, Submit & Tel ] and moved to a new abstract INPUT which is used to extend all <INPUT> fields from a base abstract input. Tests cleaned up and all attributes are now just controlled by attributes, not custom properties.
- 0.1.5 - Allow numerical strings for select options.
- 0.1.4 - Removed default as not implemented and not really suitable for this library. Also included the option to set custom name attributes to fields, falling back to the key (id) if not set.
- 0.1.3 - Added in the Checkbox Group field
- 0.1.2 - Various bug fixes
- 0.1.1 - Various bug fixes