Skip to content
Allows instantiation of custom form wrappers.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Tests
examples
src/anekdotes
.gitignore
.styleci.yml
.travis.yml
LICENSE
README.MD
composer.json
gulpfile.js
package.json
phpunit.xml
styler.php_cs

README.MD

Anekdotes Form Wrapper

Latest Stable Version Build Status codecov.io StyleCI License Total Downloads Codacy Badge

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.

You can’t perform that action at this time.