2017 © Pedro Peláez
 

library form

image

ppi/form

  • Thursday, July 3, 2014
  • by dragoonis
  • Repository
  • 2 Watchers
  • 3 Stars
  • 677 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

The PPI Form Component

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., (*1)

``` php text('username'); $form->password('password'); $form->password('confirm_password'); $form->submit('submit_button', 'Click to Continue'); ``` ### Getting Elements Getting the element when you make it ``` php text('username'); ``` Get the element at a later date ``` php $form->text('username'); $usernameElement = $form->get('username'); ``` ### Creating an element and setting attributes on it ``` php text('username') ->attr('class', 'username-field') ->attr('id', 'username-field'); ``` ### Creating an element and setting its value ``` php text('username')->setValue($userEntity->getUsername()); ``` ### Rendering Elements Each element object has a ``__toString()`` method aliased to ``render()`` so you can just echo the objects to render them Controller Code ``` php render('....', compact('form')); ?>, (*2)


Template Code ``` php <div class="username-container"> <?= $form->getElement('username'); ?> </div>

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. ``` php <?php $form = new Form(); $form->text('username');, (*3)

$entity = new UserEntity($userHelper->getByID($userID)); $form->bind($entity->toArray());, (*4)


### Creating custom elements As long as your element imeple,ented ``ElementInteface`` then you can add it to the form. ``` php <?php $element = new CustomElement(); $element->setValue($someValue); $element->attr('id', 'custom-element'); $form->addElement($element);

An example of your custom element ``` php <?php, (*5)

use PPI\Form\Element\ElementInterface;, (*6)

class CustomElement implements ElementInterface { protected $type = 'CustomElement';, (*7)

// .. implement the methods in ElementInterface

} ```, (*8)

The Versions

03/07 2014

dev-master

9999999-dev

  Sources   Download

The Requires

 

The Development Requires

03/07 2014

1.0

1.0.0.0

  Sources   Download

The Requires

 

The Development Requires