Giter Club home page Giter Club logo

former's Introduction

Former - a PHP 5.4+ Form Macro Package

An ultra simple HTML form element builder, for PHP 5.4+

Usage

To use the package, just create an instance of Spanky\Former\ElementFactory from which you will create the form elements with.

use Spanky\Former\ElementFactory as FormerElementFactory;

$former = new FormerElementFactory();

Creating Elements

To create a new form element, call the appropriate method on the ElementFactory instance. The only required parameter for each element type is the name. Once casted to a string (e.g. via an echo) the object will equal the compiled HTML of the element.

Text Inputs

$former->text('input_name', 'value', ['class' => 'myClass', 'id' => 'myId']);

Hidden inputs

$former->hidden('input_name', 'value', ['class' => 'myClass', 'id' => 'myId']);

File inputs

$former->file('input_name', ['class' => 'myClass', 'id' => 'myId']);

Email inputs

$former->email('input_name', 'value', ['class' => 'myClass', 'id' => 'myId']);

Select Boxes

$former->select('input_name', ['Option 1', 'Option 2'], 'value', ['class' => 'myClass', 'id' => 'myId']);

Calling the placeholder() method on a select box element will prepend an additional <option></option> tag to the list contained within, with an empty value by default.

Other inputs

To create other <input> elements, call the input() method, passing the desired input type as the first parameter.

$former->input('color', 'color_picker', ['Option 1', 'Option 2'], 'value', ['class' => 'myClass', 'id' => 'myId']);

Setting attributes with method chaining

Instead of passing an array of attributes when creating the element, they can be set after the object is initialised, via method the attr() method.

$former->text('name')->attr('class', 'myClass')->attr('id', 'myId');

Attributes can also be set by calling the method of the attribute you wish to set, passing in the value as the only parameter.

$former->text('name')->class('myClass');

former's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.