PHP code example of marvin255 / serviform

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

    

marvin255 / serviform example snippets





use marvin255\serviform\helpers\FactoryFields;

$form = FactoryFields::initElement('form', [
    'name' => 'feedback',
    'elements' => [
        'name' => [
            'label' => 'Name',
            'type' => 'input',
            'attributes' => [
                'class' => 'class',
                'data-attribute' => 'some attribute',
            ],
        ],
        'email' => [
            'label' => 'Email',
            'type' => 'input',
        ],
        'message' => [
            'label' => 'Message',
            'type' => 'textarea',
        ],
        'send' => [
            'label' => 'Send',
            'type' => 'button',
        ],
    ],
    'rules' => [
        [['name', 'email', 'message'], '

if ($form->loadData() && $form->validate()) {
    //get data form form
    $formData = $form->getValue();
    //here is some action if form's data is valid, e.g. mail() or redirect
}

echo $form;


use marvin255\serviform\helpers\FactoryField;

$form = FactoryFields::initElement('form', [
    'name' => 'feedback',
    'elements' => [
        'message' => [
            'type' => 'form',
            'elements' => [
                'name' => [
                    'label' => 'Name',
                    'type' => 'input',
                ],
                'email' => [
                    'label' => 'Email',
                    'type' => 'input',
                ],
                'message' => [
                    'label' => 'Message',
                    'type' => 'textarea',
                ],
            ],
            'rules' => [
                [['name', 'email', 'message'], ' => [
            'type' => 'button',
            'label' => 'Send',
        ],
    ],
]);

if ($form->loadData() && $form->validate()) {
    //get data form form
    $formData = $form->getValue();
    //here is some action if form's data is valid, e.g. mail() or redirect
}

echo $form;


use marvin255\serviform\helpers\FactoryField;

$form = FactoryFields::initElement('form', [
    'name' => 'feedback',
    'elements' => [
        'message' => [
            'type' => 'form',
            'elements' => [
                'name' => [
                    'label' => 'Name',
                    'type' => 'input',
                ],
                'email' => [
                    'label' => 'Email',
                    'type' => 'input',
                ],
                'message' => [
                    'label' => 'Message',
                    'type' => 'textarea',
                ],
            ],
            'rules' => [
                [['name', 'email', 'message'], 't',
                    ],
                ],
                'rules' => [
                    [['country', 'city', 'street'], '

use serviform\helpers\FactoryFields;

FactoryFields::setDescription('new_field_type', [
    'type' => '\My\Awesome\Field', //     'class' => 'form-control',
    ],
]);

use serviform\helpers\FactoryFields;

FactoryFields::setDescription('input', [
    'type' => '\My\Awesome\Input', // we can set new class for builtin field types
    'label' => 'Default label', // we can set any default setting for each of newly created fields
]);

use serviform\helpers\FactoryValidators;

FactoryValidators::setDescription('new_rule', [
    'type' => '\My\Awesome\Rule', // 

use serviform\helpers\FactoryValidators;

FactoryFields::setDescription(' rule
    'skipOnError' => true, // we can set any default setting for each of newly created rules
]);