Download the PHP package user-meta/html without Composer
On this page you can find all versions of the php package user-meta/html. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download user-meta/html
More information about user-meta/html
Files in user-meta/html
Package html
Short Description PHP class for html form builder
License MIT
Homepage https://github.com/khaledsaikat/html-form
Informations about the package html
Html-Form
Lightweight PHP classes to generate html elements.
This package does not have any dependency other than php-5.4
- License: MIT
Requirements
- PHP 5.4.0 or above
Installation
Composer
Composer is a widely used dependency manager for PHP
packages. This Html-Form is available on Packagist as
user-meta/html
and can be
installed by running the composer require
command. To enable Composer for you project, refer to the
project's Getting Started
documentation.
To add this dependency using the command, run the following from within your project directory:
Get Started
A quick example of generating text input with Html-Form using composer:
Output:
Almost all types of html element can be used. (e.g: button, email, div, p etc)
Output:
Usage
Basic Usage
Accepted arguments
Most of the element accept two arguments:
$default
: Default value$attributes
: Array of attributesecho Html::text($default, attributes);
For options element like select, radio, it accept third argument as $options
$options
: Array of options. The array can contains key-value pair or only valuesecho Html::select($default, attributes, $options);
using name, id and class
To assign name, id, class or any other attributes, use second arguments ($attributes
)
A text field with default value, name, id and class attributes:
Output:
Add attributes to element
You can also add any attributes into any element:
Output:
using required, readonly and disabled
Output:
Using label
Output:
A div with id and class attributes:
Output:
lebel with label text, id, class and for attributes
Output:
Using checkbox
Simple checkbox with default checked
Output:
Pass first argument as false for default unchecked. echo Html::checkbox(false)
List of checkbox
Create a list of checkboxes with default values
Output
To get array of values by POST or GET method
Output
Using select / radio
Create a select with default value, name and id attributes
Output
Create a list of radio
Output
Using collection
Several elements can be grouped together as collection
Output:
Collection uses Html
constructor and accept two parameters.
$type
(optional): name of tag. (e.g. form, div)$attributes
(optional): array of attributes
Form example
Generating a form using collections:
Output:
Nested collections
Generating html template using nested collections:
Using as xml generator
Output
Advanced
It is possible to create any html element by calling their name.
Under the hood, we use Html::input()
for input element and Html::tag()
for html tag
Create an email input by using input
method:
Create h1 by using tag
method:
Add html to before and after elements
Output
Enclose with another element.
Output
several way to set options for select / multiselect / radio / checkbox
Output
Mixing several way with one options array
Output
Using numeric value
Output
Security
Escaping Output
Escaping means stripping out unwanted data, like malformed HTML or script tags.
The library apply esc_attr
to value attribute. esc_url
to href
and src
attributes.