PHP code example of anekdotes / formwrapper

1. Go to this page and download the library: Download anekdotes/formwrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anekdotes / formwrapper example snippets


    $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());

    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());