dev-master
9999999-dev https://github.com/livecms/formsLive CMS Forms
MIT
The Requires
by Mokhamad Rofiudin
v0.0.1
0.0.1.0 https://github.com/livecms/formsLive CMS Forms
MIT
The Requires
by Mokhamad Rofiudin
Live CMS Forms
This package can make form component (ie. textbox, select, radio, checkbox) based on array of setting., (*1)
Besides that, You can also create your own component consist of html and javascript., (*2)
composer require livecms/forms
php artisan vendor:publish --provider="LiveCMS\Form\FormServiceProvider"
Edit 'form.php' config file., (*3)
// controller use LiveCMS\Form\Forms; $form = Forms::create()->setComponents([...])->render(); // view {!! Form::open(['url' => '/your/route']) !!} {!! $form !!} {!! Form::close() !!}
in form : it has same arguments for Form::open() in LaravelCollective HTML, (*4)
// controller $form = Forms::create(['url' => '/your/route', 'method' => 'PUT', 'class' => 'form-inline']) ->setComponents([...]) ->render(); // view {!! $form !!}
// controller Forms::create([...])->setComponents([...])->setName('form1'); Forms::create([...])->setComponents([...])->setName('form2'); // view {!! Form::render('form1') !!} {!! Form::render('form2') !!}
you can see the files in folder :, (*5)
/vendor/livecms/forms/src/Components
$components = [ 'comp1' => [ 'type' => 'text', // required 'label' => null, // optional 'value' => null, // 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' => [ 'required' => true, 'class' => 'input-select', ] ] ]; Form::create([...])->setComponents($components)->setName('form1');
Forms::create([...]) ->setComponents([...]) ->addGlobalProperties([ 'required' => '*', // implemented to all components, you can use empty array [] 'class:input-select' => ['province', 'city', 'region'], 'data-image: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" /> */
/vendor/livecms/forms/src/Components/BaseComponent.php
Since it contains an abstract method render(), you have to define your own render() method.
You can also see the example from available components or extends from it. See all files in folder
/vendor/livecms/forms/src/Components
'components' => [
'text' => \App\Forms\CustomeTextbox::class,
'image' => \App\Forms\CustomeImage::class,
],
Forms::create([...])->setComponents([...])->useValidation()->setName('form1');
You can disable validation by :, (*6)
Forms::create([...])->setComponents([...])->useValidation(false)->setName('form1');
Note : by default, validation script require jquery validation js, (*7)
php
'scripts' => [
'validation' => '/path/to/javascript/file',
],
php
'scripts' => [
'validation' => '/path/to/javascript/file',
'customscript' => '/path/to/javascript/file',
],
php
Forms::create([...])->setComponents([...])->addScript('customscript')->setName('form1');
If you want to cancel adding script, fill second argument with 'false':, (*8)
->addScript('script_name', false)
$components = [ 'name' => ['type' => 'text'], 'email' => ['type' => 'email'], ]; $datas = ['name' => 'Mokhamad Rofiudin', 'email' => 'mokh@rofiudin.com']; Form::create([...]) ->setComponents($components) ->fill($datas) ->setName('form1') ->render();
MIT, (*9)
Fork this repo and make a pull request, (*10)
Please create new issue or see the closed issues too., (*11)
Live CMS Forms
MIT
Live CMS Forms
MIT