anekdotes / formwrapper
Allows wrapping of form controls.
Installs: 537
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Language:CSS
Requires
- php: >=7.4.0
- anekdotes/support: *
Requires (Dev)
- phpunit/phpunit: ^9
README
Allows instantiation of standardized custom form wrappers. Eases extandability of new wrappers.
Installation
Install via composer into your project:
composer require anekdotes/formwrapper
Please note that using composer allows easy namespacing for using classes later on. Following examples use a composer based namespace autoloading.
Basic Usage
$form = new Anekdotes\FormWrapper\Form; echo($form->open('www.toaster.com', post, ["class" => "form"])); echo($form->Text('label', 'toaster', ["class" => "form-stuff"], 'val')); echo($form->close());
will output
<form action="www.toaster.com" method="form" class="form"> <input type="text" name="toaster" value="val class="form-stuff" /> </form>
All built-in Controls and Wrappers can be found in the folder examples
. To have the required namespaces autoloaded, you will need to run composer install
Extending Controls and Wrappers
It is possible to write your own controls and wrappers and use them.
namespace MyCustomWrapper; use Anekdotes\FormWrapper\Wrappers\Wrapper; class MyWrapper extends Wrapper { public function handle($input, $title = '') { return '<div class="MyCustomLabel">'.$title.'</div><div>'.$input.'</div>'; } }
namespace MyCustomControl; use Anekdotes\FormWrapper\Controls\Control; class MyControl extends Control { protected $nbParams = 1; public function prepare($arguments) { $name = $arguments[0]; return '<input type="text" value="'.$name.'" name="'.$name.'"/>'; } }
$form = new Anekdotes\FormWrapper\Form; $form->wrappersNamespace = 'MyCustomWrapper//'; $form->controlsNamespace = 'MyCustomControl//'; echo($form->open('www.toaster.com', post, ["class" => "form"])); echo($form->MyControl('toaster', 'toaster', 'MyWrapper')); echo($form->close());
Contributing
Pull requests are welcome. Note that if you want to develop the scss files, you will need to install npm dependencies using npm install
. You will then need to use gulp
to compile the CSS.
Pull requests must have tests included (excepted for the scss). If no tests are to be found, if the pull request does not pass the current test suite or if the tests do not cover enough cases, the pull requests may not be merged.
Examples
The folder /examples contains PHP examples of a lot of wrappers in use. (pre-built + customs).
To see them in browser, you'll need to bootup a php server pointing on the examples folder and running composer install
at the root of this project.
Note
Most of the pre-built wrappers use css classes from Bootstrap.