![License MIT][badge-license]
![PHP 7 Supported][badge-php]
![Code Climate][badge-code-climate]
, (*1)
Coordinates form validation, errors, messages, values, and inputs in a DRY KISS way., (*2)
Installation
Add the following to your composer.json
file., (*3)
``` bash
{
"require": {
"bootpress/form": "^1.0"
}
}, (*4)
## Example Usage
```php
<?php
use BootPress\Form\Component as Form;
$form = new Form('form', 'post');
// Create some menus
$form->menu('gender', array(
'M' => 'Male',
'F' => 'Female',
));
$form->menu('remember', array('Y' => 'Remember Me'));
// Set the default values
$form->set('values', array(
'name' => 'Daniel',
'email' => 'me@example.com',
'gender' => 'M',
));
Now the form's menus and default values have been set up, and you have a $form->validator
object filled with $_POST
vars, ready to go. You don't have to use the BootPress Validator Component, but it sure makes things easier for you., (*5)
$form->validator->set(array(
'name' => 'required',
'email' => 'required|email',
'gender' => 'required|inList',
'password' => 'required|minLength[5]|noWhiteSpace',
'confirm' => 'required|matches[password]',
'feedback' => 'maxWords[2]',
'remember' => 'yesNo',
));
if ($vars = $form->validator->certified()) {
echo '
'.print_r($vars, true).'
';
// $form->eject();
}
When you create a $form->menu()
, we automatically pass it's values to the validator so that you can $form->validator->set('field', 'inList')
with no params, and still be covered. That's why we didn't put 'inList[M,F]' for your gender above. To create the form:, (*6)
echo $form->header();
echo $form->fieldset('Form', array(
$form->text('name', array('class' => 'form-control')),
$form->text('email', array('placeholder' => 'Email Address')),
$form->radio('gender'),
$form->password('password'),
$form->password('confirm'),
$form->textarea('feedback'),
$form->checkbox('remember'),
$form->input('submit', array('name' => 'Submit')),
));
echo $form->close();
That would give you the following HTML:, (*7)
You may want to put some labels and error messages in there, but this Form component is meant to be a bare-bones, just-get-the-hard-stuff-done first, so that you can style it anyway you like., (*8)
License
The MIT License (MIT). Please see License File for more information., (*9)