2017 © Pedro Peláez
 

library forms

Framework agnostic form helpers

image

werx/forms

Framework agnostic form helpers

  • Monday, June 6, 2016
  • by joshmoody
  • Repository
  • 5 Watchers
  • 8 Stars
  • 3,636 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 18 Versions
  • 2 % Grown

The README.md

werx\Forms

Build Status Total Downloads Latest Stable Version Code Climate, (*1)

Framework agnostic form helpers., (*2)

About

I've never found form libraries terribly useful. In my experience, they either work only for the most simple forms, or end up being way more difficult to use than just writing the HTML by hand., (*3)

That said, I do need some really basic form helpers to easily pre-populate form fields (like from previous POST to correct errors or from a database) and build drop down boxes., (*4)

The primary goal of this library is to solve those 2 problems in a way I don't hate. If I can make some more robust form helpers that don't get in my way while I'm at it, all the better., (*5)

This library provides helpers for setting default values in otherwise static html form elements as well as an input builder for dynamically creating form elements., (*6)

Quick Examples

You can view the full documentation with more examples at http://werx.moody.io/packages/forms/, (*7)

Here's a few quick examples to get you started., (*8)


Text boxes

``` php , (*9)


``` php <?=Form::text('username')?>

Selects

``` php , (*10)


``` php <?=Form::select('state')->data(['TX' => 'Texas', 'AR' => 'Arkansas', 'OK' => 'Oklahoma'])->label('Choose')?>
<?=Form::select('color')->data(['Red', 'White', 'Blue'], true)->selected('White')?>

Checkboxes and Radios

``` php /> Cat /> Dog /> Fish, (*11)


``` php <input type="radio" name="color" value="Red" <?=Form::getChecked('color', 'Red')?> /> Red <input type="radio" name="color" value="Blue" <?=Form::getChecked('color', 'Blue')?> /> Blue <input type="radio" name="color" value="Green" <?=Form::getChecked('color', 'Green')?> /> Green

``` php =Form::checkbox('pets')->value('Cat')?> Cat =Form::checkbox('pets')->value('Dog')->checked()?> Dog =Form::checkbox('pets')->value('Fish')?> Fish, (*12)


``` php <?=Form::radio('color')->value('Red')?> Red <?=Form::radio('color')->value('Blue')->checked()?> Blue <?=Form::radio('color')->value('Green')?> Green

Use the checkedWhen() method if you want to check something pending some condition. Pass any condition you like. If it evaluates to true, it will call checked() on the element., (*13)

``` php =Form::radio('color')->value('Red')->checkedWhen($some_value == 'Red')?> Red =Form::radio('color')->value('Blue')->checkedWhen($some_value == 'Blue')?> Blue =Form::radio('color')->value('Green')->checkedWhen($some_value == 'Green')?> Green, (*14)

> `checkedWhen()` works for both radios and checkboxes.

## Installation
This package is installable and autoloadable via Composer as [werx/forms](https://packagist.org/packages/werx/forms). If you aren't familiar with the Composer Dependency Manager for PHP, [you should read this first](https://getcomposer.org/doc/00-intro.md).

```bash
$ composer require werx/forms --prefer-dist

Contributing

Unit Testing

$ composer test

Coding Standards

This library uses PHP_CodeSniffer to ensure coding standards are followed., (*15)

I have adopted the PHP FIG PSR-2 Coding Standard EXCEPT for the tabs vs spaces for indentation rule. PSR-2 says 4 spaces. I use tabs. No discussion., (*16)

To support indenting with tabs, I've defined a custom PSR-2 ruleset that extends the standard PSR-2 ruleset used by PHP_CodeSniffer. You can find this ruleset in the root of this project at PSR2Tabs.xml, (*17)

Execute the codesniffer command from the root of this project to run the sniffer using these custom rules and codefixer command to correct them., (*18)

$ composer codesniffer
$ composer codefixer

The Versions

06/06 2016

dev-master

9999999-dev

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

06/06 2016

1.8.3

1.8.3.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

27/10 2015

1.8.2

1.8.2.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

26/10 2015

1.8.1

1.8.1.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

27/08 2015

dev-select-multiple

dev-select-multiple

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

27/08 2015

1.8.0

1.8.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

18/03 2015

1.7.1

1.7.1.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

13/03 2015

1.7.0

1.7.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

04/02 2015

1.6.0

1.6.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

03/02 2015

1.5.0

1.5.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

01/02 2015

1.3.1

1.3.1.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

01/02 2015

1.4.0

1.4.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

01/02 2015

1.3.0

1.3.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

26/01 2015

1.2.0

1.2.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

23/01 2015

1.1.0

1.1.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

04/11 2014

1.0.1

1.0.1.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

04/09 2014

0.1.0

0.1.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input

04/09 2014

1.0

1.0.0.0

Framework agnostic form helpers

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Josh Moody

form helper input