PHP code example of livecms / forms

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

    

livecms / forms example snippets


// controller

use LiveCMS\Form\Forms;

$form = Forms::create()->setComponents([...])->render();

// view
{!! Form::open(['url' => '/your/route']) !!}
{!! $form !!}
{!! Form::close() !!}

<script>
{!! Form::javascript()  !!}
</script>

// controller
$form = Forms::create(['url' => '/your/route', 'method' => 'PUT', 'class' => 'form-inline'])
            ->setComponents([...])
            ->render();

// view
{!! $form !!}
<script>
{!! Form::javascript()  !!}
</script>

// controller
Forms::create([...])->setComponents([...])->setName('form1');
Forms::create([...])->setComponents([...])->setName('form2');

// view
{!! Form::render('form1') !!}
{!! Form::render('form2') !!}

<script>
{!! Form::javascript()  !!}
</script>

$components = [
    'comp1' => [
        'type' => 'text', //  // optional
        'default' => null, // optioal
        'options' => [], // optional and this only for checkbox, radio, select, select2
        'attributes' => [], // optional
    ],
    ...
    'comp-n' => [
        'type' => 'select',
        'options' => [
            'one', 'two', 'three',
        ],
        'attributes' => [
            '

Forms::create([...])
    ->setComponents([...])
    ->addGlobalProperties([
        'landscape' => ['image', 'cover'],
    ])
    ->setName('form1');

// the result all of defined components will get what you write in key of the array
// example for : 'data-image:landscape' => ['image', 'cover']
// the result  :
/**
 * <input type="file" name="image" data-image="landscape" />
 * <input type="file" name="cover" data-image="landscape" />
 */

Forms::create([...])->setComponents([...])->useValidation()->setName('form1');

Forms::create([...])->setComponents([...])->useValidation(false)->setName('form1');

        'scripts' => [
            'validation' => '/path/to/javascript/file',
        ],
    

        'scripts' => [
            'validation' => '/path/to/javascript/file',
            'customscript' => '/path/to/javascript/file',
        ],
    

    Forms::create([...])->setComponents([...])->addScript('customscript')->setName('form1');
    

->addScript('script_name', false)

$components = [
    'name' => ['type' => 'text'],
    'email' => ['type' => 'email'],
];
$datas = ['name' => 'Mokhamad Rofiudin', 'email' => '[email protected]'];
Form::create([...])
    ->setComponents($components)
    ->fill($datas)
    ->setName('form1')
    ->render();
shell
php artisan vendor:publish --provider="LiveCMS\Form\FormServiceProvider"

    /vendor/livecms/forms/src/Components/BaseComponent.php