corneltek/formkit

1.4.0 2017-06-26 02:40 UTC

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads

使用 FormKit 库,您可以集成表单小部件到自己的框架中,

当然,您也可以轻松地为您的应用程序定义自己的表单小部件。

厌倦了 HTML 表单?有一些小部件布局引擎可以将小部件渲染为 HTML 表格或字段集/图例。当然,您也可以定义自己的布局引擎!

安装

composer require corneltek/formkit "^1.3"

使用方法

要使用文本输入小部件

$text = new FormKit\Widget\TextInput('username', array( 
    'label' => 'Username',
    'placeholder' => 'Your name please',
    'hint'  => 'Please enter 6 characters for your username',
));
$text->value( 'default' )
    ->size(20);

echo $text; // render 

它将输出

<input type="text" name="username" value="default" placeholder="Your name please" size="20"/>
<div class="formkit-hint">Please enter 6 characters for your username</div>

SelectInput

/* selector with group options */
$countries = new FormKit\Widget\SelectInput( 'country' , array(
    'label' => 'Country',
    'options' => array(
        'Test' => 'Test',
        'Asia' => array( 
            'Taiwan',
            'Taipei',
            'Tainan',
            'Tokyo',
            'Korea',
        )
    )
));

元素 API

use FormKit\Element;
$ul = new Element('ul');
$li = new Element('li');

$li->append( new Element('a') );
$li->appendText( "DOMText Node here" );

$li->addClass('item');
$li->setId('MyID');

$li->appendTo($ul);

echo $li->render();

布局

要使用通用布局

$layout = new FormKit\Layout\GenericLayout;
$layout->width(400);
$layout->addWidget( $text )
    ->addWidget( $password )
    ->addWidget( $remember )
    ->addWidget( $birthday )
    ->addWidget( $best_time )
    ->addWidget( $role )
    ->addWidget( $size )
    ->addWidget( $countries )
    ->cellpadding(6)
    ->cellspacing(6)
    ->border(0);
echo $layout;

小部件工厂

表单小部件工厂

use FormKit\FormKit;
$username = FormKit::text('username');
$password = FormKit::password('password',array( 
    'class' => 'your-element-class-name',
    'id' =>  'your-element-id',
    'value' => 'default password',
));

echo $username->render();
echo $password->render();

开标签 & 关标签

$form = new FormKit\Element\Form(array(
    'class' => 'blah blah'
));

// render elements manully
echo $form->open();
echo $form->renderChildren();
echo $form->close();

// which is equal to
echo $form->render();

可用的表单小部件

  • TextareaInput
  • TextInput
  • ButtonInput
  • CheckboxInput
  • ColorInput
  • DateInput
  • DatetimeInput
  • FileInput
  • HiddenInput
  • Label
  • PasswordInput
  • RadioInput
  • ResetInput
  • SelectInput
  • SubmitInput
  • AjaxCompleteInput
  • CanvasInput

安装

安装示例资产

$ assetkit install

许可证

MIT 许可证