您好,登錄后才能下訂單哦!
小編給大家分享一下如何使用PHP實現動態表單生成工具,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
表單包含多種input類型,包括 hiiden類型 ,text類型,radio類型,checkbox類型,textarea類型,file類型,select類型等基礎類型,手寫表單就是累耗時耗力開發銷量太低而且代碼量大了還容易寫出bug,每個頁面的表單遇到改動的時候恨不得長十雙手去改,于是我自己開發了一個php寫的表單生成工具,在業務邏輯通過配置或者鏈式操作去初始表單結構和數據,不管有多少頁面都只需要通過配置下就行,我寫的這個表單工具 支持塊表單,行內表單,table類型表單,支持表單美化 默認是layui效果,也支持jquery控制表單行為,只需要引入layui樣式和js即可。在github主頁demo目錄也提供了示例代碼運行查看效果,
使用php編寫的html表單生成工具,沒有任何依賴可獨立使用,支持鏈式操作和配置創建表單,支持表單美化(默認為layui風格)
沒有任何依賴可獨立使用
支持鏈式操作創建表單
支持數組配置創建表單
支持塊表單
支持行內表單
支持table表單
支持表單美化(默認為layui風格)且方便擴展
github: https://github.com/mgckid/form
gitee:https://gitee.com/mgckid/form
composer require mgckid/form
<?php require __DIR__ . '/../src/Form.php'; Form::getInstance() ->form_method(Form::form_method_post) ->form_action('/') ->input_text('姓名', '', 'name', '法外狂徒張三') ->radio('性別', '', 'male', ['male' => '男', 'female' => '女'], 'male') ->checkbox('愛好', '', 'interest', ['ktv' => 'K歌', 'dance' => '跳舞', 'movie' => '看電影', 'run' => '跑步'], 'ktv,run') ->input_inline_start() ->input_text('省份', '', 'sheng', '湖北省') ->input_text('市', '', 'shi', '武漢市') ->input_text('區', '', 'qu', '武昌區') ->input_text('街道', '', 'jie', '紫陽路36號') ->input_inline_end() ->input_hidden('id', '1') ->input_text('user name', '', 'user', 'admin') ->input_password('password', '', 'password', '123456') ->radio('is active', '', 'is_active', [ ['value' => '1', 'name' => 'active'], ['value' => '0', 'name' => 'unactive'] ], 1) ->checkbox('user role', '', 'role', [ ['value' => '1', 'name' => 'boss'], ['value' => '2', 'name' => 'manager'], ['value' => '3', 'name' => 'employee'], ], '1,2') ->select('user department', '', 'department', [ ['value' => '1', 'name' => 'sales'], ['value' => '2', 'name' => 'hr'], ['value' => '3', 'name' => 'secured'], ], 1) ->form_class(LayuiForm::form_class_pane) ->input_submit('確認保存', 'class="layui-btn" lay-submit lay-filter="saveBtn"') //->input_date() //->editor() //->form_data() //->table() ->create(); ?>
<?php require __DIR__ . '/../src/Form.php'; $init = array( 0 => array( 'title' => 'Id', 'name' => 'id', 'description' => 'Id', 'enum' => array(), 'type' => 'hidden', 'widget_type' => '', ), 1 => array( 'title' => '用戶id', 'name' => 'user_id', 'description' => '用戶id', 'enum' => array(), 'type' => 'hidden', 'widget_type' => '', ), 2 => array( 'title' => '用戶名', 'name' => 'username', 'description' => '用戶名', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 3 => array( 'title' => '真實姓名', 'name' => 'true_name', 'description' => '真實姓名', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 4 => array( 'title' => '密碼', 'name' => 'password', 'description' => '密碼', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 5 => array( 'title' => '郵箱', 'name' => 'email', 'description' => '郵箱', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 6 => array( 'title' => '是否刪除', 'name' => 'deleted', 'description' => '是否刪除', 'enum' => array( 0 => '未刪除', 1 => '已刪除', ), 'type' => 'none', 'widget_type' => '', ), 7 => array( 'title' => '創建時間', 'name' => 'created', 'description' => '創建時間', 'enum' => array(), 'type' => 'none', 'widget_type' => 'date', ), 8 => array( 'title' => '修改時間', 'name' => 'modified', 'description' => '修改時間', 'enum' => array(), 'type' => 'none', 'widget_type' => 'date', ), ); $data = array( 'id' => 2, 'user_id' => 'feac0fa3-3245-11e6-9b90-e03f49a02407', 'username' => 'admin', 'true_name' => '系統管理員', 'email' => '', 'deleted' => 0, 'created' => '2016-06-14 23:39:52', 'modified' => '2020-03-12 20:07:48', ); \Form::getInstance() ->form_schema($init) ->form_data($data) ->input_submit('確認保存', 'class="layui-btn" lay-submit lay-filter="saveBtn"') ->create();
<?php require __DIR__ . '/../src/Form.php'; $init = array( 0 => array( 'title' => 'Id', 'name' => 'id', 'description' => 'Id', 'enum' => array(), 'type' => 'hidden', 'widget_type' => '', ), 1 => array( 'title' => '用戶id', 'name' => 'user_id', 'description' => '用戶id', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 2 => array( 'title' => '用戶名', 'name' => 'username', 'description' => '用戶名', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 3 => array( 'title' => '真實姓名', 'name' => 'true_name', 'description' => '真實姓名', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 4 => array( 'title' => '密碼', 'name' => 'password', 'description' => '密碼', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 5 => array( 'title' => '郵箱', 'name' => 'email', 'description' => '郵箱', 'enum' => array(), 'type' => 'text', 'widget_type' => '', ), 6 => array( 'title' => '是否刪除', 'name' => 'deleted', 'description' => '是否刪除', 'enum' => array( 0 => '未刪除', 1 => '已刪除', ), 'type' => 'none', 'widget_type' => '', ), 7 => array( 'title' => '創建時間', 'name' => 'created', 'description' => '創建時間', 'enum' => array(), 'type' => 'none', 'widget_type' => 'date', ), 8 => array( 'title' => '修改時間', 'name' => 'modified', 'description' => '修改時間', 'enum' => array(), 'type' => 'none', 'widget_type' => 'date', ), ); \Form::getInstance() ->input_inline_start() ->form_schema($init) ->input_submit('<i class="layui-icon"></i> 搜索', ' class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"', 'class="layui-btn layui-btn-primary"') ->input_inline_end() ->form_class(\LayuiForm::form_class_pane) ->form_method(Form::form_method_get) ->create();
<?php require __DIR__ . '/../src/Form.php'; $form_init = array ( 'id' =>array ( 'title' => '主鍵', 'name' => 'id', 'description' => '主鍵', 'enum' =>array(), 'type' => 'hidden', 'widget_type' => '', ), 'name' =>array ( 'title' => '配置名稱', 'name' => 'name', 'description' => '配置名稱', 'enum' =>array(), 'type' => 'text', 'widget_type' => '', ), 'description' =>array ( 'title' => '配置描述', 'name' => 'description', 'description' => '配置描述', 'enum' =>array(), 'type' => 'text', 'widget_type' => '', ), 'input_type' =>array ( 'title' => '表單類型', 'name' => 'input_type', 'description' => '表單類型', 'enum' =>array ( 'hidden' => '隱藏域', 'select' => '下拉', 'radio' => '單選按鈕', 'text' => '文本', 'textarea' => '多行文本', 'file' => '上傳', 'none' => '非表單', 'editor' => '富文本', 'checkbox' => '復選框', 'date' => '日期', ), 'type' => 'select', 'widget_type' => '', ), 'created' =>array ( 'title' => '創建時間', 'name' => 'created', 'description' => '創建時間', 'enum' =>array(), 'type' => 'none', 'widget_type' => 'date', ), 'modified' =>array ( 'title' => '修改時間', 'name' => 'modified', 'description' => '修改時間', 'enum' =>array(), 'type' => 'none', 'widget_type' => 'date', ), 'deleted' =>array ( 'title' => '刪除標記', 'name' => 'deleted', 'description' => '刪除標記', 'enum' =>array ( 0 => '未刪除', 1 => '已刪除', ), 'type' => 'none', 'widget_type' => '', ), ); $form_data=array ( 0 => array ( 'id' => 73, 'name' => 'solution_introduction', 'value' => '111', 'description' => '解決方案介紹', 'input_type' => 'textarea', 'created' => '2018-12-07 11:44:40', 'modified' => '2022-03-08 00:32:08', 'deleted' => 0, ), 1 => array ( 'id' => 72, 'name' => 'tese_product_introduction', 'value' => '222', 'description' => '特色產品介紹', 'input_type' => 'textarea', 'created' => '2018-12-07 11:43:52', 'modified' => '2022-03-08 00:32:09', 'deleted' => 0, ), 2 => array ( 'id' => 71, 'name' => 'new_product_introduction', 'value' => '333', 'description' => '新產品介紹', 'input_type' => 'textarea', 'created' => '2018-12-07 11:41:37', 'modified' => '2022-03-08 00:32:09', 'deleted' => 0, ), 3 => array ( 'id' => 70, 'name' => 'site_pinterest', 'value' => '', 'description' => 'Pinterest堪稱圖片版的Twitter鏈接', 'input_type' => 'text', 'created' => '2018-11-19 11:48:12', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ), 4 => array ( 'id' => 69, 'name' => 'site_twitter', 'value' => '', 'description' => 'Twitter(非官方漢語通稱推特)鏈接', 'input_type' => 'text', 'created' => '2018-11-19 11:47:04', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ), 5 => array ( 'id' => 68, 'name' => 'site_facebook', 'value' => '', 'description' => 'Facebook(臉書)鏈接', 'input_type' => 'text', 'created' => '2018-11-19 11:46:07', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ), 6 => array ( 'id' => 67, 'name' => 'site_google_plus', 'value' => '', 'description' => 'Google+SNS社交網站鏈接', 'input_type' => 'text', 'created' => '2018-11-19 11:45:26', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ), 7 => array ( 'id' => 66, 'name' => 'site_linkedin', 'value' => '', 'description' => 'LinkedIn領英鏈接', 'input_type' => 'text', 'created' => '2018-11-19 11:43:53', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ), 8 => array ( 'id' => 65, 'name' => 'site_livechat_code', 'value' => '', 'description' => 'livezilla在線客服代碼', 'input_type' => 'textarea', 'created' => '2018-11-15 16:45:15', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ), 9 => array ( 'id' => 64, 'name' => 'site_skype', 'value' => '', 'description' => '聯系skype', 'input_type' => 'text', 'created' => '2018-11-15 16:44:40', 'modified' => '2019-04-27 14:08:07', 'deleted' => 0, ) ); \Form::getInstance() ->table('擴展配置', '', 'site_config', $form_init, $form_data) ->create();
以上是“如何使用PHP實現動態表單生成工具”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。