PHP code example of jnjxp / form

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

    

jnjxp / form example snippets


$form = (new Jnjxp\Form\FieldFactory)->newFieldCollection();

$form->add('username')
    ->type('text')
    ->label('Username')
    ->attribs([' => true]);

$data = $filter->apply($input);
$form->fill($data);
$form->errors($filter->getFailures()->getMessages());


foreach ($form as $field) {

    $group = ['form-group'];
    $label = ['class' => 'control-label'];

    if ($field->id) {
        $group[] = 'form-group_' . $field->id;
        $label['for'] = $field->id;
    }

    if ($field->errors) {
        $group[] = 'has-errors';
    }

    echo $helper->tag('div', ['class' => $group]);

    if ($field->label) {
        echo PHP_EOL;
        echo $helper->label($field->label, $label);
    }

    echo PHP_EOL;
    echo $helper->input($field->spec);

    if ($field->help) {
        echo PHP_EOL;
        echo $helper->tag('p', ['class' => 'help-block']);
        echo $field->help;
        echo $helper->tag('/p');
    }

    if ($field->errors) {
        $errors = $helper->ul(['class' => 'errors']);
        $errors->items($field->errors);
        echo PHP_EOL;
        echo $errors;
        echo PHP_EOL;
    }

    echo $helper->tag('/div') . PHP_EOL;
    echo PHP_EOL;
}