1. Go to this page and download the library: Download moirei/fields 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/ */
use MOIREI\Fields\Inputs\Field;
use MOIREI\Fields\Inputs\{Text, Number, Select, Radio, Textarea};
...
$survey_questions = [
Text::make('Whats your name?', 'name')
->rules('max:24')
->placeholder('John Doe')
->toArray(),
Number::make('How old are you?', 'age')
->min(18)
->toArray(),
Select::make('Gender')
->options([
'Fridge',
'Bridge',
[ 'text' => 'I prefer not to say', 'value' => 'other' ],
])
->default('other')
->toArray(),
Radio::make('Can keep you data for future promos?', 'subscribe')
->trueValue('Yes plez')
->falseValue('No thanks')
->toArray(),
Textarea::make('More about yourself?', 'more')
->rows(10)
->hint('In a few words. Feel free to elaborate on the above.')
->persistentHint()
->toArray(),
];
$field = Text::make('Whats your name?', 'name')
->rules('max:24')
->placeholder('John Doe');
$valid = $field->validate('James Bond');
// or assert and throw exception
$field->validate('James Bond', true)