thinkphp5 form 表单生成器

浏览:6886 最后更新:2017-02-21 11:49 分类:类库 关键字: thinkphp5 form 表单生成器

###扩展安装
    composer require zouxiang0639/form-builder如果大家都需要ajax提交的话我就加个ajax提交方法

欢迎加群讨论(489771818)
一个表单生成器,不继承任何一个扩展包;
thinkphp5 form 表单生成器
可以快速方便的生成form表单,减写多余代码,减写多余的判断,提升开发速度,

packagist https://packagist.org/packages/zouxiang0639/tform-builder
github https://github.com/zouxiang0639/form-builder
扩展参考 laraver illuminate/html https://github.com/illuminate/html

-----

### 函数查询 /**
 * @method mixed token() public token
 * @method mixed close() public 关闭一个HTML表单
 * @method mixed setModel(mixed $model) public 设置HTML表单模型
 * @method mixed open(array $options) public 打开一个新的HTML表单
 * @method mixed button(string $value = null, array $options = array()) public 表单button
 * @method mixed file(string $name, array $options = array()) public 表单file
 * @method mixed model(mixed $model ,array $options = array()) public 打开一个新的HTML表单模型
 * @method mixed submit(string $value = null, array $options = array()) public 表单submit提交
 * @method mixed text(string $name, string $value = null, array $options = []) public 表单text
 * @method mixed label(string $name, string $value = null, array $options = []) public label标签
 * @method mixed url(string $name, string $value = null, array $options = array()) public 表单url
 * @method mixed email(string $name, string $value = null, array $options = array()) public 表单email
 * @method mixed reset(string $name, string $value = null, array $options = array()) public 表单reset
 * @method mixed hidden(string $name, string $value = null, array $options = array()) public 表单hidden
 * @method mixed image(string $url, string $name = null, array $attributes = array()) public 表单image提交
 * @method mixed textarea(string $name, string $value = null, array $options = array()) public 表单textarea
 * @method mixed password(string $name, string $value = null, array $options = array()) public 表单password
 * @method mixed checkbox(string $name, string $value = 1, string $checked = null, array $options = array()) public 表单checkbox
 * @method mixed radio(string $name, string $value = null, string $checked = null, array $options = array())) public 表单radio
 * @method mixed select(string $name, array $list = array(), string $selected = null, array $options = array()) public 表单textarea
 * @method mixed selectYear(string $name ,string $begin,string $end, string $selected = null ,array $options = array()) public select年
 * @method mixed selectMonth(string $name ,string $selected = null ,array $options = array() ,string $format = '%m') public select月
 */
###案例
案例 
<?php
    require __DIR__ . '/vendor/autoload.php';
    $post = $_POST;
    //  $form  = think\form\Form::form();  //静态初始化 FormBuilder
    $form  = form();                   //函数初始化 FormBuilder
    ?>

    <div class="bs-example">
        <?=$form->open(['files'=>true])?>
        <table class="table table-bordered">
            <tbody>
            <tr>
                <th>text</th>
                <th>
                    <?=$form->text('text',array_get($post,'text'),['class'=>'form-control','style'=>'width: 100px'])?>
                </th>
            </tr>
            <tr>
                <th width="150">file</th>
                <td>
                    <?=$form->file('file')?>
                </td>
            </tr>
            <tr>
                <th width="150">label</th>
                <td>
                    <?=$form->label('label','label标签')?>
                </td>
            </tr>
            <tr>
                <th>button</th>
                <td>
                    <?=$form->button('按钮')?>
                </td>
            </tr>
            <tr>
                <th>url</th>
                <td>
                    <?=$form->url('url',array_get($post,'url'),['placeholder'=>'http://localhost'])?>
                </td>
            </tr>
            <tr>
                <th>email</th>
                <td>
                    <?=$form->email('email',array_get($post,'email'),['placeholder'=>'123@qq.com'])?>
                </td>
            </tr>
            <tr>
                <th>hidden</th>
                <td>
                    <?=$form->hidden('hidden','hidden')?>
                </td>
            </tr>
            <tr>
                <th>password</th>
                <td>
                    <?=$form->password('password',['placeholder'=>'请输入密码'])?>
                </td>
            </tr>
            <tr>
                <th>checkbox</th>
                <td>
                    复选题: A<?=$form->checkbox('checkbox','A',array_get($post,'checkbox'))?>
                    B<?=$form->checkbox('checkbox','B',array_get($post,'checkbox'))?>
                    C<?=$form->checkbox('checkbox','C',array_get($post,'checkbox'))?>
                </td>
            </tr>
            <tr>
                <th>radio</th>
                <td>
                    单选题: A<?=$form->radio('radio','A',array_get($post,'radio'))?>
                    B<?=$form->radio('radio','B',array_get($post,'radio'))?>
                    C<?=$form->radio('radio','C',array_get($post,'radio'))?>
                </td>
            </tr>
            <tr>
                <th>token</th>
                <td>
                    <?=$form->token()?>
                </td>
            </tr>
            <tr>
                <th>select</th>
                <td>
                    <?=$form->select('select',['select1','select2','select3'],array_get($post,'select'))?>
                </td>
            </tr>
            <tr>
                <th>select2</th>
                <td>
                    <?=$form->select('select1',['select1'=>['select11','select12','select13'],'select2','select3'],array_get($post,'select1'))?>
                </td>
            </tr>
            <tr>
                <th>selectYear</th>
                <td>
                    <?=$form->selectYear('selectYear',2012,2017,array_get($post,'selectYear'))?>
                </td>
            </tr>
            <tr>
                <th>selectMonth</th>
                <td>
                    <?=$form->selectMonth('selectMonth',array_get($post,'selectMonth'))?>
                </td>
            </tr>
            <tr>
                <th>selectMonth</th>
                <td>
                    <?=$form->textarea('textarea',array_get($post,'textarea'))?>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="form-actions col-sm-12" style="margin-bottom: 40px">
        <?=$form->submit('保存',['class'=>'btn btn-primary'])?>
        <?=$form->image('http://www.thinkphp.cn//Uploads/editor/2017-01-19/5880236ed217b.png')?>
        <?=$form->reset('重置',['class'=>'btn btn-default'])?>
    </div>

<?=$form->close()?>
评论( 相关
后面还有条评论,点击查看>>