Skip to content

Commit 7d5848d

Browse files
committed
0.1;
1 parent b5ddf4c commit 7d5848d

File tree

3 files changed

+488
-92
lines changed

3 files changed

+488
-92
lines changed

README.md

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,60 @@
11
# php-form-builder
2-
php表单构建类
2+
3+
> php表单构建类
4+
5+
### 使用示例demo
6+
7+
demo.php
8+
```php
9+
<?php
10+
11+
require_once "php-form-builder/vendor/autoload.php";
12+
13+
$config = [
14+
'ns' => 'we',
15+
'name' => 'form',
16+
'form_class' => ['form' , 'form-ajax'],
17+
'action' => 'http://www.action.com',
18+
'method' => 'GET',
19+
'upload_file' => false
20+
];
21+
22+
$form = new \niklaslu\FormBuilder($config);
23+
24+
$html = $form->addClass('form-class')
25+
->setAction('http://action.com')
26+
->setMethod('post')
27+
->uploadFile()
28+
->addText('name' , '名称' , '' , '前填写您的名称' , true , '' , 'group1')
29+
->addPassword('password' , '密码' , '' , '请输入密码' , true , '请输入6-10位数字密码' , 'group1')
30+
->addEmail('email' , '邮箱' , '' , '请输入邮箱' , true)
31+
->addNumber('sort' , '排序' , 0 )
32+
->addTextarea('info' , '内容' , '' , '请填写内容' , true)
33+
->addFile('file' , '文件' )
34+
->addButton('button' , '按钮' , '哈哈')
35+
->addSelect('sex' , '选择' , 2 , [1=>'男' , 2=> '女'])
36+
->addRadio('radio' , '单选' , 1 , ['1' => 'yi' , 2 => 'er' , 3 => 'shan'])
37+
->addCheckbox('checkbox[]' , '多选' , ['1',2] ,[1 => 'yi' , 2 => 'er' , 3 => 'shan'] )
38+
->addSubmit('提交')
39+
->addReset('重置')
40+
->addGroup('group1' , '分组1')
41+
->build();
42+
43+
echo $html;
44+
45+
// 默认不需配置config
46+
$form = new \niklaslu\FormBuilder();
47+
48+
$html = $form->setFormName('form-1')
49+
->setFormNs('we')
50+
->setAction('http://action1.com')
51+
->setMethod('get')
52+
->addGroup('group2' , '基础信息')
53+
->addText('name' , '名称' , '' , '前填写您的名称' , true , '' , 'group2')
54+
->addPassword('password' , '密码' , '' , '请输入密码' , true , '请输入6-10位数字密码' , 'group2')
55+
->addSubmit('ok')
56+
->build();
57+
58+
echo $html;
59+
60+
```

demo.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Administrator
5+
* Date: 2017/3/22
6+
* Time: 16:04
7+
*/
8+
require_once "./vendor/autoload.php";
9+
10+
$config = [
11+
'ns' => 'we',
12+
'name' => 'form',
13+
'form_class' => ['form' , 'form-ajax'],
14+
'action' => 'http://www.action.com',
15+
'method' => 'GET',
16+
'upload_file' => false
17+
];
18+
19+
$form = new \niklaslu\FormBuilder($config);
20+
21+
$html = $form->addClass('form-class')
22+
->setAction('http://action.com')
23+
->setMethod('post')
24+
->uploadFile()
25+
->addText('name' , '名称' , '' , '前填写您的名称' , true , '' , 'group1')
26+
->addPassword('password' , '密码' , '' , '请输入密码' , true , '请输入6-10位数字密码' , 'group1')
27+
->addEmail('email' , '邮箱' , '' , '请输入邮箱' , true)
28+
->addNumber('sort' , '排序' , 0 )
29+
->addTextarea('info' , '内容' , '' , '请填写内容' , true)
30+
->addFile('file' , '文件' )
31+
->addButton('button' , '按钮' , '哈哈')
32+
->addSelect('sex' , '选择' , 2 , [1=>'' , 2=> ''])
33+
->addRadio('radio' , '单选' , 1 , ['1' => 'yi' , 2 => 'er' , 3 => 'shan'])
34+
->addCheckbox('checkbox[]' , '多选' , ['1',2] ,[1 => 'yi' , 2 => 'er' , 3 => 'shan'] )
35+
->addSubmit('提交')
36+
->addReset('重置')
37+
->addGroup('group1' , '分组1')
38+
->build();
39+
40+
echo $html;
41+
42+
// 默认不需配置config
43+
$form = new \niklaslu\FormBuilder();
44+
45+
$html = $form->setFormName('form-1')
46+
->setFormNs('we')
47+
->setAction('http://action1.com')
48+
->setMethod('get')
49+
->addGroup('group2' , '基础信息')
50+
->addText('name' , '名称' , '' , '前填写您的名称' , true , '' , 'group2')
51+
->addPassword('password' , '密码' , '' , '请输入密码' , true , '请输入6-10位数字密码' , 'group2')
52+
->addSubmit('ok')
53+
->build();
54+
55+
echo $html;

0 commit comments

Comments
 (0)