PHP code example of qingbing / pf-widgets-form-generator
1. Go to this page and download the library: Download qingbing/pf-widgets-form-generator 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/ */
qingbing / pf-widgets-form-generator example snippets
class TestForm extends FormOption
{
/**
* 定义的表单项目
* @return mixed
*/
public function getOptions()
{
return [
[
'code' => 'password',
'label' => '设置密码',
'input_type' => \FormGenerator::INPUT_TYPE_PASSWORD,
// 'data_type' => \FormGenerator::DATA_TYPE_PASSWORD, // default
'allow_empty' => false,
],
[
'code' => 'comparePassword',
'label' => '确认密码',
'input_type' => \FormGenerator::INPUT_TYPE_PASSWORD,
'data_type' => \FormGenerator::DATA_TYPE_COMPARE,
'compare_field' => 'password',
'allow_empty' => false,
],
[
'code' => 'sex',
'label' => '性别',
'input_type' => \FormGenerator::INPUT_TYPE_SELECT,
// 'data_type' => \FormGenerator::DATA_TYPE_SELECT, // default
'input_data' => [
'10000' => '密',
'10001' => '男',
'10002' => '女',
],
'allow_empty' => false,
],
[
'code' => 'hobby',
'label' => '爱好',
'input_type' => \FormGenerator::INPUT_TYPE_SELECT,
'data_type' => \FormGenerator::DATA_TYPE_CHOICE,
'max' => 3,
'min' => 2,
'input_data' => [
'10001' => '跑步',
'10002' => '登山',
'10003' => '游泳',
'10004' => '写字',
'10005' => '唱歌',
],
'allow_empty' => false,
],
[
'code' => 'checked',
'label' => '是否同意',
'input_type' => \FormGenerator::INPUT_TYPE_CHECKBOX, // 输入类型无需数据类型,最特殊的一个,其实隐藏为range
'allow_empty' => false,
],
[
'code' => 'fruit',
'label' => '水果',
'input_type' => \FormGenerator::INPUT_TYPE_CHECKBOX_LIST,
// 'data_type' => \FormGenerator::DATA_TYPE_CHOICE, // 只有一种数据类型
'min' => 2,
'max' => 3,
'input_data' => [
'10001' => '苹果',
'10002' => '桌子',
'10003' => '梨子',
'10004' => '香蕉',
],
'allow_empty' => false,
],
[
'code' => 'avatar',
'label' => '头像',
'input_type' => \FormGenerator::INPUT_TYPE_FILE,
// 'data_type' => \FormGenerator::DATA_TYPE_FILE, // 只有一种数据类型
'file_extensions' => 'jpg|jpeg|png',
'allow_empty' => false,
],
[
'code' => 'lover',
'label' => '最爱的水果',
'input_type' => \FormGenerator::INPUT_TYPE_RADIO_LIST,
// 'data_type' => \FormGenerator::DATA_TYPE_CHECKED, // 只有一种数据类型
'input_data' => [
'10001' => '苹果',
'10002' => '梨子',
'10003' => '香蕉',
],
'allow_empty' => false,
],
[
'code' => 'content',
'label' => '内容',
'input_type' => \FormGenerator::INPUT_TYPE_EDITOR,
'allow_empty' => false,
],
[
'code' => 'hidden',
'label' => '隐藏域',
'input_type' => \FormGenerator::INPUT_TYPE_HIDDEN,
'data_type' => \FormGenerator::DATA_TYPE_STRING,
'default' => "hide",
'allow_empty' => false,
],
[
'code' => 'description',
'label' => '描述',
'input_type' => \FormGenerator::INPUT_TYPE_TEXTAREA,
'data_type' => \FormGenerator::DATA_TYPE_STRING,
'default' => "This is description",
'allow_empty' => true,
],
[
'code' => ''整数',
'input_type' => \FormGenerator::INPUT_TYPE_TEXT,
'data_type' => \FormGenerator::DATA_TYPE_INTEGER,
'allow_empty' => false,
],
[
'code' => 'preg_field',
'label' => '正则匹配',
'input_type' => \FormGenerator::INPUT_TYPE_TEXT,
'data_type' => \FormGenerator::DATA_TYPE_PREG,
'pattern' => '/\d{2,4}/',
'allow_empty' => false,
],
[
'code' => 'string_field',
'label' => '字符串',
'input_type' => \FormGenerator::INPUT_TYPE_TEXT,
'data_type' => \FormGenerator::DATA_TYPE_STRING,
'allow_empty' => false,
],
];
}
}
$this->widget('\Widgets\FormGenerator', [
'model' => $model,
]);