FORMS

#GET & POST

Skilldo cung cấp các phương pháp trợ giúp cho phép bạn lấy các mục POST, GET. Lợi thế chính của việc sử dụng các phương pháp được cung cấp thay vì lấy trực tiếp là các biến sẽ được kiểm tra xem có tồn tại không và được lộc bảo mật trước khi trả về. Điều này cho phép bạn sử dụng dữ liệu thuận tiện mà không cần phải kiểm tra xem một mục tồn tại trước tiên

Lấy giá trị biến $_GET

static function InputBuilder::Get( $key, $args);

Lấy giá trị biến $_POST

static function InputBuilder::Post( $key, $args);

Params

(array) $args
        clear :: true/false (default true) - Xóa các tag html
        type :: text/int (default text) - Chuyển dữ liệu về kiểu text or int

#Example

domain/?skilldo=Si%C3%AAu%20%3Cb%3EKinh%3C/b%3E%20Doanh%20%3Cscript%3Ealert(%27a%27)%3C/script%3E');
InputBuilder::Get('skilldo');

// Siêu Kinh Doanh alert('a')

Hủy clear code html

InputBuilder::Get('skilldo', ['clear' => true]);

// Siêu <b>Kinh</b> Doanh [removed]alert&#40;'a'&#41;[removed]

#BUILDER

Use

Sử dụng class FormBuilder để build cả form

$FormBuilder = new FormBuilder();

Thêm một đối tượng vào Form

$FormBuilder->add($name, $type, $args, $value)

Hiển thị hoặc trả về mã html

$FormBuilder->html($result)
// $result = true : trả về giá trị html
// $result = false: in ra mã html

Sử dụng static render để hiển thị từng input

FormBuilder::render($args, $value)

Field Type

Các loại form element được hỗ trợ

Các loại type đặc biệt

#Type text, password, number, email, url, textarea, hidden

->add('field_name', 'text', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type checkbox, radio

->add('field_name', 'checkbox', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
    'single' => true,
    'options' => [
        'value1' => 'Checkbox Label 1',
        'value2' => 'Checkbox Label 2',
        'value3' => 'Checkbox Label 3'
    ]
])

#Type on/off (true/false)

->add('field_name', 'switch', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type color

->add('field_name', 'color', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type image/file

->add('field_name', 'image', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type wysiwyg, wysiwyg-short

->add('field_name', 'wysiwyg', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type date, datetime

->add('field_name', 'date', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type cate

->add('field_name', 'cate_{cate_type}', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type post

->add('field_name', 'post_{post_type}', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type page

->add('field_name', 'page', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type menu

->add('field_name', 'menu', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])
->add('field_name', 'gallery', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
])

#Type Select image

->add('field_name', 'select-img', [
    'label'       => __('Field name'),
    'class'       => 'field-class',
    'id'         => 'field-id',
    'placeholder'   => __('Placeholder'),
    'options' => [
        'value1' => [
            'label' => 'name value 1',
            'img' => url_img_value_1
        ],
        'value2' => [
            'label' => 'name value 2',
            'img' => url_img_value_2
        ],
        'value3' => [
            'label' => 'name value 3',
            'img' => url_img_value_3
        ],
    ]
])

#Type html

->add('', 'html', 'code html')

#Type Repeater

Kiểu input được hỗ trợ từ phiên bản cms 4.4.3

->add('item', 'repeater', ['label' => 'Label Test', 'fields' => [
    ['name' => 'title', 'type' => 'text',  'label' => __('Tiêu đề'), 'col' => 6, 'language' => true],
    ['name' => 'image', 'type' => 'image', 'label' => __('Images'), 'col' => 6],
    ['name' => 'des', 'type' => 'textarea', 'label' => __('Mô tả'), 'col' => 12, 'language' => true],
]]);

#Type popover

Danh sách tin tức

->add('field_name', 'popover', [
    'label'     => '__('Field name'),
    'module'    => 'post',
    'key_type'  => 'post',
    'multiple'  => true,
    'image'     => true,
    'placeholder'   => __('Placeholder'),
])

Danh sách danh mục sản phẩm

->add('field_name', 'popover', [
    'label'     => '__('Field name'),
    'module'    => 'products_categories',
    'key_type'  => 'products_categories',
    'multiple'  => true,
    'image'     => true,
    'placeholder'   => __('Placeholder'),
])

Danh sách sản phẩm

->add('field_name', 'popover', [
    'label'     => '__('Field name'),
    'module'    => 'products',
    'key_type'  => 'products',
    'multiple'  => true,
    'image'     => true,
    'placeholder'   => __('Placeholder'),
])

Danh sách sản phẩm variable

->add('field_name', 'popover', [
    'label'     => '__('Field name'),
    'module'    => 'products_variable',
    'key_type'  => 'products_variable',
    'multiple'  => true,
    'image'     => true,
    'placeholder'   => __('Placeholder'),
])

#Type popover advance

Version hỗ trợ từ phiên bản cms 4.6.0

Các tham số đặc biệt

Parameter Value Description
search string Đối tượng tìm kiếm hoặc ajax lấy dữ liệu
load string Method trả về danh sách dữ liệu đã chọn
taxonomy string post_type hoặc cate_type khi cần search dữ liệu post hoặc category
template string Id template hiển thị dữ liệu khi search
template_load string Id template hiển thị dữ liệu khi đã chọn
multiple bool | true Cho phép chọn nhiều hoặc duy nhất một dữ liệu

Danh sách post

->add('field_name', 'popover-advance', [
    'label'     => __('Field name'),
    'search'    => 'post',
    'placeholder'   => __('Placeholder'),
])

Danh sách category

->add('field_name', 'popover-advance', [
    'label'     => __('Field name'),
    'search'    => 'category',
    'placeholder'   => __('Placeholder'),
])

Danh sách page (trang nội dung)

->add('field_name', 'popover-advance', [
    'label'     => __('Field name'),
    'search'    => 'page',
    'placeholder'   => __('Placeholder'),
])

Template search mặc định

<script id="popover_advance_search_template" type="text/x-custom-template">
    <div data-id="${id}" data-item="${data}" class="popover_advance__item clearfix">
        <div class ="item">
            <div class ="item__image"><img src ="${image}"></div>
            <div class ="item__name">${name}</div>
        </div>
    </div>
</script>

* Điều kiện khi viết template search mới phải giữ lại bộ khung sau:

<script id="popover_advance_search_template" type="text/x-custom-template">
    <div data-id="${id}" data-item="${data}" class="popover_advance__item clearfix">
        //Template search
    </div>
</script>

Template load mặc định

<script id="popover_advance_load_template" type="text/x-custom-template">
    <div data-id="${id}" class="popover_advance__item_result popover_advance__item_result_${id} clearfix">
        <div class="item">
            <input type="checkbox" name="${field}" value="${id}" checked>
            <div class="item__image"><img src="${image}"></div>
            <div class="item__name">${name}</div>
            <div class="item__action"><button class="btn btn-red item__btn_delete" type="button"><i class="fal fa-times"></i></button></div>
        </div>
    </div>
</script>

* Điều kiện khi viết template load mới phải giữ lại bộ khung sau:

<script id="popover_advance_load_template" type="text/x-custom-template">
    <div data-id="${id}" class="popover_advance__item_result popover_advance__item_result_${id} clearfix">
        <div class="item">
            <input type="checkbox" name="${field}" value="${id}" checked>
            //Template
            <div class="item__action"><button class="btn btn-red item__btn_delete" type="button"><i class="fal fa-times"></i></button></div>
        </div>
    </div>
</script>

Khi truyền biến search bằng ajax dữ liệu trả về bắt buộc có các trường:

Parameter Value Description
total number Tổng dữ liệu khi search
items array Danh sách item kết quả search, trong item bắt buộc có id và data (mã hóa htmlentities(json_encode($item)) của chính item đó)