2017 © Pedro Peláez
 

library forms

Live CMS Forms

image

livecms/forms

Live CMS Forms

  • Sunday, July 22, 2018
  • by mrofi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Welcome to Laravel Form Component For Laravel 5.5 or above

What is ?

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)

Features

  • All benefits of LaravelCollective HTML packages
  • Create form and the components based array of settings
  • Support Jquery Validation
  • Available Components that ready to use :
    • Textbox
    • Telephone
    • Number
    • Email
    • Password
    • Textarea
    • Checkbox
    • Radio
    • Select
    • Select2
    • Image
    • Boolean (Radio button with Yes/No options)
  • Define your own component
  • Define your own validation script

Notes

How to use?

Install via composer

composer require livecms/forms

Publish config file :

php artisan vendor:publish --provider="LiveCMS\Form\FormServiceProvider"

Edit 'form.php' config file., (*3)

Creating form :

// controller

use LiveCMS\Form\Forms;

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

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






Set

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 !!}





You can create multiple forms and set a name for each form :

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

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






Available components :

you can see the files in folder :, (*5)

/vendor/livecms/forms/src/Components
  • Textbox, type : 'text'
  • Telephone, type : 'tel'
  • Number, type : 'number'
  • Email, type : 'email'
  • Password, type : 'password'
  • Textarea, type : 'textarea'
  • Checkbox, type : 'checkbox'
  • Radio, type : 'radio'
  • Select, type : 'select'
  • Select2, type : 'select2'
  • Image, type : 'image'
  • Boolean, type : 'boolean'

How to use 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');

Add global properties :

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" />
 */

Add custom component :

  • Create a Class, you can extends a class from 'LiveCMS\Form\Components\BaseComponent' class in /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
  • Define your custome components in 'form' config file : 'components' => [ 'text' => \App\Forms\CustomeTextbox::class, 'image' => \App\Forms\CustomeImage::class, ],

Use Validation Script

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)

Custom Validation

  • Create your own javascript file
  • Define it in 'form' config file : php 'scripts' => [ 'validation' => '/path/to/javascript/file', ],

Add custom scripts

  • Create your own javascript file
  • Define it in 'form' config file, but use other name despite 'validation' because it is reserved only for validation : php 'scripts' => [ 'validation' => '/path/to/javascript/file', 'customscript' => '/path/to/javascript/file', ],
  • Call it 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)

Fill form with datas

$components = [
    'name' => ['type' => 'text'],
    'email' => ['type' => 'email'],
];
$datas = ['name' => 'Mokhamad Rofiudin', 'email' => 'mokh@rofiudin.com'];
Form::create([...])
    ->setComponents($components)
    ->fill($datas)
    ->setName('form1')
    ->render();

LICENSE

MIT, (*9)

CONTRIBUTING

Fork this repo and make a pull request, (*10)

ISSUE AND DISCUSSION

Please create new issue or see the closed issues too., (*11)

The Versions

22/07 2018

dev-master

9999999-dev https://github.com/livecms/forms

Live CMS Forms

  Sources   Download

MIT

The Requires

 

by Mokhamad Rofiudin

22/07 2018

v0.0.1

0.0.1.0 https://github.com/livecms/forms

Live CMS Forms

  Sources   Download

MIT

The Requires

 

by Mokhamad Rofiudin