PHP code example of corneltek / formkit

1. Go to this page and download the library: Download corneltek/formkit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corneltek / formkit example snippets


$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 

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

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