An extendable, flexible form widget generator for PHP without framework dependency. form widgets can be easily layout with layout renderers.
PHP JavaScript Other
Latest commit 82589e7 Jun 21, 2016 @c9s c9s committed on GitHub Update README.md
Permalink
Failed to load latest commit information.
assets
demo
doc
src Remove top level directory for PSR-4 class loading Jun 21, 2016
static/js
tests Disable selenium tests Jun 21, 2016
.assetkit
.gitignore Add .gitignore Mar 30, 2012
.travis.yml
LICENSE
README.md
build.xml
composer.json
package.ini
package.xml bump version to 1.3.0 Feb 14, 2013
phpdox.xml
phprelease.ini
phpunit-ci.xml
phpunit.xml Add phpunit.xml.dist Jun 21, 2016
phpunit.xml.dist

README.md

FormKit

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

With FormKit library, you can integrate form widgets with your own frameworks,

And of course, you can define your own form widgets for your applications easily.

Tired with HTML forms ? There are some widget layout engines that can render widget into HTML with HTML table or fieldsets/legends. Of course you can define your own layout engine too!

INSTALL

composer require corneltek/formkit "^1.3"

USAGE

To use a text input widget:

$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 

Which outputs:

<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',
        )
    )
));

Element 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

To use generic layout:

$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;

Widget Factory

Form Widget Factory:

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();

Open Tag & Close Tag

$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();

Availabel Form Widgets

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

Installation

Install assets for demo:

$ assetkit install

License

MIT License