tuhin18003/codeigniter-form-builder

轻松在Codeigniter框架中创建表单。

安装: 45

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:codeigniter-library

v1.0.0 2018-03-12 20:39 UTC

This package is auto-updated.

Last update: 2024-09-23 01:10:24 UTC


README

该项目正在快速开发中,目前处于早期alpha阶段。它是创建Codeigniter开发中表单的简单方法。

安装

最新版

在开发过程中,您可以通过将form_builder的版本要求设置为dev-master,来跟踪master分支的最新更改。

{
   "require": {
      "tuhin18003/codeigniter-form-builder": "dev-master"
   }
}

通过命令行

composer require tuhin18003/codeigniter-form-builder

如何使用

您可以在代码中非常容易地使用它,并轻松创建bootstrap表单,无需在视图文件中编写html。

基本表单示例

public function index()
{
  $this->load->helper('form');
            
  $form = new \Cs_form\Cs_form();
  $bootstrap = $form->Bootstrap();
            
  $inputs = $bootstrap->generate_basic_form(array(
  	'action' => 'test',
        'attributes' => array( 'class' => 'formclass', 'id' => 'myform' ),
        'fields' => array(
        	array(
                	'type'          => 'text',
                        'label'         => array( 'text' => 'What is your Name', 'id' => 'username', 'attribute' => array( 'class' => '')),
                        'input'          => array(
                            'name'          => 'username',
                            'id'            => 'username',
                            'value'         => 'johndoe',
                            'class'         => 'form-control'
                        )
                    )
                )
            ));
            
   $this->load->view( 'welcome_message', array( 'inputs' => $inputs ) );
}

内联表单示例

 $inputs = $bootstrap->generate_inline_form(array(
  	'action' => 'test',
        'attributes' => array( 'id' => 'myform' ),
        'fields' => array(
        	array(
                	'type'          => 'text',
                        'label'         => array( 'text' => 'What is your Name', 'id' => 'username', 'attribute' => array( 'class' => '')),
                        'input'          => array(
                            'name'          => 'username',
                            'id'            => 'username',
                            'value'         => 'johndoe',
                            'class'         => 'form-control'
                        )
                    )
                )
            ));

水平表单示例

$inputs = $bootstrap->generate_horizontal_form(array(
  	'action' => 'test',
        'attributes' => array( 'id' => 'myform' ),
        'fields' => array(
        	array(
                	'type'          => 'text',
                        'label'         => array( 'text' => 'What is your Name', 'id' => 'username', 'attribute' => array( 'class' => 'col-sm-2 control-label')),
                        'input'          => array(
                            'name'          => 'username',
                            'id'            => 'username',
                            'value'         => 'johndoe',
                            'class'         => 'form-control',
                            'input_wrap_class' => 'col-sm-10'
         )
      )
   )
));