There is no license information available for the latest version (1.0) of this package.

1.0 2014-07-03 14:39 UTC

This package is not auto-updated.

Last update: 2023-03-18 07:25:16 UTC


Creating Elements

To create elements, you access the appropriate method for that element type. Alternatively you can use the underlying add() or addElement(ElementInteface $element) methods.

$form = new Form();


$form->submit('submit_button', 'Click to Continue');

Getting Elements

Getting the element when you make it

$form = new Form();
$usernameElement = $form->text('username');

Get the element at a later date

$usernameElement = $form->get('username');

Creating an element and setting attributes on it

$form = new Form();

    ->attr('class', 'username-field')
    ->attr('id', 'username-field');

Creating an element and setting its value

$form = new Form();

Rendering Elements

Each element object has a __toString() method aliased to render() so you can just echo the objects to render them

Controller Code

$form = new Form();
// ... add elements
return $this->render('....', compact('form'));

Template Code

<div class="username-container">
<?= $form->getElement('username'); ?>

Binding Data To Your Form

When toArray() is called on your entity, you will have a data key for username which will match the name of the text field added named username.

$form = new Form();

$entity = new UserEntity($userHelper->getByID($userID));

Creating custom elements

As long as your element imeple,ented ElementInteface then you can add it to the form.

$element = new CustomElement();
$element->attr('id', 'custom-element');


An example of your custom element


use PPI\Form\Element\ElementInterface;

class CustomElement implements ElementInterface
    protected $type = 'CustomElement';
    // .. implement the methods in ElementInterface