Skip to content

Instantly share code, notes, and snippets.

@sigaev-pro
Last active August 29, 2015 14:22
Show Gist options
  • Save sigaev-pro/44dd66594627f206aaa6 to your computer and use it in GitHub Desktop.
Save sigaev-pro/44dd66594627f206aaa6 to your computer and use it in GitHub Desktop.
<?php namespace App\Forms;
use Kris\LaravelFormBuilder\Form;
class FormFieldForm extends Form
{
public function buildForm()
{
$this
->add('name', 'text', [
'label' => 'Название',
'required' => true,
'wrapper' => ['class' => 'form-group col-md-6'],
])
->add('alias', 'text', ['label' => 'Алиас', 'wrapper' => ['class' => 'form-group col-md-6']])
->add('required', 'checkbox', ['label' => 'Обязательное поле', 'wrapper' => ['class' => 'form-group col-md-12']])
->add('type', 'select', ['label' => 'Тип', 'wrapper' => ['class' => 'form-group col-md-6'],
'choices' => [
'text' => 'text',
'email' => 'email',
'textarea' => 'textarea',
'number' => 'number',
'tel' => 'tel',
'date' => 'date',
'month' => 'month',
'range' => 'range',
'checkbox' => 'checkbox',
'radio' => 'radio',
'select' => 'select',
'choice' => 'choice'
],
'empty_value' => '=== выберите тип поля ===',
'selected' => function ($data) {
return array_pluck($data, 'type');
}
])
->add('description', 'text', ['label' => 'Описание', 'wrapper' => ['class' => 'form-group col-md-6']])
->add('order', 'number', ['label' => 'Порядок', 'wrapper' => ['class' => 'form-group col-md-6']])
->add('options', 'textarea', ['label' => 'Опции (JSON)', 'wrapper' => ['class' => 'form-group col-md-12']]);
}
}
<?php namespace App\Forms;
use Kris\LaravelFormBuilder\Form;
class FormForm extends Form
{
public function buildForm()
{
$this
->add('name', 'text', [
'label' => 'Название',
'required' => true,
])
->add('alias', 'text', ['label' => 'Алиас'])
->add('description', 'text', ['label' => 'Описание'])
->add('hr', 'static', [
'label' => false,
'tag' => 'hr', // Tag to be used for holding static data,
// 'attr' => ['class' => 'form-control-static'], // This is the default
// 'default_value' => 'Static Text' // If nothing is passed, data is pulled from model if any
])
->add('fields', 'collection', [
'type' => 'form',
'label' => false,
'prototype' => false,
'options' => [
'class' => 'App\Forms\FormFieldForm',
'wrapper' => ['class' => 'row item-block'],
'label' => false
]
])
->add('Сохранить', 'submit',
[
'attr' => ['class' => 'btn btn-primary']
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment