PHP code example of okneloper / forms

1. Go to this page and download the library: Download okneloper/forms 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/ */

    

okneloper / forms example snippets


class Model {
    public $name;
    public $type;
}

$form = new \Okneloper\Forms\Form(new Model);
$form->add('text', 'name', 'Name');
$form->add('select', 'type', 'Type')->options([
    'foo' => 'Bar',
    'baz' => 'FooBar',
]);

if ($request->isPost()) {
    $app = \Illuminate\Support\Facades\App::getFacadeApplication();
    $rules = [
        'name' => 'dated POST values
    } else {
        $errors = $form->getValidator()->getErrorMessages();
    }
}

$form->add('button', 'btn', 'ClickMe'); // <buttont type="button"...>ClickMe</button>
$form->add('submitButton', 'btn', 'Submit'); // <buttont type="submit">Submit</button>




$form = new \Okneloper\Forms\Form();

$form->add('text', 'fname');
$form->add('text', 'lname');
$form->add('submitButton', 'Submit');

// this is how data might come from a submitted form
$data = [
    'fname' => 'John',
    'lname' => 'Smith',
    'Submit' => '1',
];

$form->submit($data);

print_r($form->modelToArray());