2017 © Pedro Peláez
 

library html

HTML helper for easy way form building from any PHP code

image

jbzoo/html

HTML helper for easy way form building from any PHP code

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

JBZoo Html Build Status Coverage Status

HTML helper for easy way form building from any PHP code., (*1)

License Latest Stable Version Scrutinizer Code Quality, (*2)

Install

composer require jbzoo/html:"1.x-dev"  # Last version
composer require jbzoo/html            # Stable version

How to use?

require_once './vendor/autoload.php'; // composer autoload.php

// Get needed classes
use JBZoo\Html\Html;

echo Html::_('input')->render( /* ... */ ); // Underscore as factory

$html = Html::getInstance();                // Create or get pimple container
echo $html['input']->render( /* ... */ );   // As array
echo $html->input->render( /* ... */ );     // As object

## 1# Html button

1.1 Simple button

echo Html::_('button')->render('test', 'Button', array('title' => 'title attr'));

```html , (*3)

#### 1.2 Change button type
```php
echo Html::_('button')->render('test', 'Button', array(), 'reset');

```html , (*4)

#### 1.3 Support UIkit CSS Framework button
```php
echo Html::_('button')->render('test', 'My button', array('button' => 'success', 'class' => 'my-class'));

```html , (*5)

#### 1.4 Support UIkit CSS Framework icon
```php
echo Html::_('button')->render('test', 'My button', array('button' => 'success', 'icon' => 'stop'));

```html , (*6)



## 2# Boolean elements ------------------------------------------------------------------------------------------------------------------------ #### 2.1 Radio buttons ```php echo Html::_('radiobool')->render('show', 0); // 0 is "No" and 1 is "Yes"

```html , (*7)

#### 2.2 Single checkbox flag
```php
echo Html::_('checkbool')->render(
    'show',                                 // Name
    0,                                      // Checked value
    array(                                  // Attrs
        'data-rel'   => 'tooltip',
        'data-title' => 'Checkbox title',
    )
);

```html , (*8)

    data-rel="tooltip"              <!-- ... and custom attrs -->
    data-title="Checkbox title"
    class="jb-val-1"
> Yes

, (*9)

## 3# Elements with list of options
------------------------------------------------------------------------------------------------------------------------
#### 3.1 Default checkbox template (No wrap)
```php
echo Html::_('checkbox')->render(
    array(                          // List of options
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',                         // Name
    array('val-1', 'val-3'),        // Checked values
    array('data-rel' => 'tooltip')  // Attrs
);

```html , (*10)

#### 3.2 Default wrap checkbox template
```php
echo Html::_('checkbox')->render(
    array(                          // List of options
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',                         // Name
    array('val-1', 'val-3'),        // Checked values
    array('data-rel' => 'tooltip')  // Attrs
);

```html , (*11)

#### 3.3 Custom checkbox template
```php
echo Html::_('checkbox')->render(
    array(                          // List of options
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',                         // Name
    'val-1',                        // Checked value
    array(),                        // Attrs
    function ($list, $name, $value, $id, $text, $attrs) {   // Custom render function
        $alias    = $value;
        $inpClass = 'jb-val-' . $alias;
        $input    = $list->input($name, $value, $id, $inpClass, $attrs);
        $text     = '<span class="label-title">' . $text . '</span>';
        $label    = $list->label($id, $alias, $text);

        return implode(PHP_EOL, array($input, $label));
    }
);

```html , (*12)

#### 3.3 Default checkbox template (No wrap)
```php
echo Html::_('radio')->render(
    array(                          // List value
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',                         // Checked value
    array('val-1', 'val-3'),
    array('data-rel' => 'tooltip')
);

```html , (*13)

#### 3.4 Default wrap checkbox template
```php
echo Html::_('radio')->render(
    array(                          // List of options
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',                         // Name
    'val-1',                        // Checked value
    array(),                        // Attrs
    true                            // Wrap input by label
);

```html , (*14)

#### 3.5 Custom radio template
```php
echo Html::_('radio')->render(
    array(
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',
    'val-1',
    array(),
    function ($list, $name, $value, $id, $text, $attrs) {
        $alias    = $value;
        $inpClass = 'jb-val-' . $alias;
        $input    = $list->input($name, $value, $id, $inpClass, $attrs);
        $text     = '<span class="label-title">' . $text . '</span>';
        $label    = $list->label($id, $alias, $text);

        return implode(PHP_EOL, array($input, $label));
    }
);

```html , (*15)

#### 3.5 Checked value is not exists
```php
echo Html::_('radio')->render(
    array(                          // List of options
        'val-1' => 'Label 1',
        'val-2' => 'Custom Label',
        'val-3' => 'Var 3',
    ),
    'test',                         // Name
    'val-8',                        // Undefined value
    array(),                        // Atrs
    true                            // Wrap inputs by labels
);

```html , (*16)



## 3# Data list ------------------------------------------------------------------------------------------------------------------------ ```php echo Html::_('datalist')->render( array( // Keys and Values 'Label' => 'Content text', 'Custom label' => 'List text', ), array( // Attrs 'class' => 'test', 'id' => 'custom', ) );

```html , (*17)

Label
Content text
Custom label
List text


## 4# Selects ------------------------------------------------------------------------------------------------------------------------ #### 4.1 Simple select list ```php echo Html::_('select')->render( array( 'val-1' => 'Label 1', 'test' => 'Label test', 'custom' => 'Custom', ), 'test', 'custom', array( 'data-title' => 'My form select', ) );

```html , (*18)

#### 4.1 Multiple select
```php
echo Html::_('select')->render(
    array(
        'val-1'  => 'Label 1',
        'test'   => 'Label test',
        'custom' => 'Custom',
        'simple' => 'Simple label',
        'moscow' => 'Moscow',
    ),
    'test',
    array('test', 'moscow'),
    array(
        'multiple' => true,
    )
);

```html , (*19)

#### 4.3 Selected option is not found
```php
/**
 * If selected params is array. For check selected option taken last array var.
 * If option is not exists created new option. See output.
 */
echo Html::_('select')->render(
    array(
        'val-1'  => 'Label 1',
        'test'   => 'Label test',
        'custom' => 'Custom',
        'simple' => 'Simple label',
        'moscow' => 'Moscow',
    ),
    'test',
    array('test', 'moscow', 'no-value')
);

```html , (*20)

#### 4.4 Select with groups
```php
echo Html::_('select')->render(
    array(
        'val-1' => 'Label 1',
        'test'  => 'Test label',
        array(
            'gr-test' => 'Group test 1',
            'val-1'   => 'No exits in group',
        )
    ),
    'test',
    array('test', 'moscow', 'no-value')
);

```html , (*21)



## 5# Hiddens fields ------------------------------------------------------------------------------------------------------------------------ #### 5.1 Single hidden input ```php echo Html::_('hidden')->render('image', 'my-value', 'my-class', 'unique', array('data-profile' => 'user-1'));

```html , (*22)

#### 5.2 Group of hidden inputs
```php
echo Html::_('hidden')->group(array(
    'my-name' => 'My name value',
    'user'    => 'Administrator',
    'array'   => array(
        'value' => 'my value',
        'class' => 'array-hidden',
        'id'    => 'hide-id',
    ),
));

```html , (*23)



## 6# Iframe ------------------------------------------------------------------------------------------------------------------------ ```php echo Html::_('iframe')->render('http://my-site.com/page', 'my-class', 'my-id', array('data-rel' => 'my-iframe'));

```html , (*24)




## 7# Textarea ------------------------------------------------------------------------------------------------------------------------ ```php echo Html::_('textarea')->render( 'test', 'Text area content', 'my-class', 'my-id', array( 'data-rel' => 'tooltip', 'data-title' => 'Enter description', ) );

```html , (*25)



## 7# Custom tag ------------------------------------------------------------------------------------------------------------------------ ```php echo Html::_('tag')->render('My content', 'custom-class', 'unique', array( 'tag' => 'div', 'title' => 'Custom title' ));

```html , (*26)

My content


## 8# Data attr builder ------------------------------------------------------------------------------------------------------------------------ ```php echo Html::_('input')->render( 'test', 'My value', '', '', array('data' => array( 'test' => 'val', 'json' => array( 'param-1' => 'val-1', 'param-2' => 'val-2', ) )) );

```html , (*27)



## Unit tests and check code style ```sh make make test-all

License

MIT, (*28)

The Versions

01/08 2016

dev-master

9999999-dev

HTML helper for easy way form building from any PHP code

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kalistratov

form html controls render inputs rendering

01/08 2016

dev-develop

dev-develop

HTML helper for easy way form building from any PHP code

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kalistratov

form html controls render inputs rendering

19/02 2016

1.0.0

1.0.0.0

HTML helper for easy way form building from any PHP code

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kalistratov

form html controls render rendering