2017 © Pedro Peláez
 

library form-object

Web Form Framework

image

reioto/form-object

Web Form Framework

  • Saturday, April 30, 2016
  • by reioto
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

form-object

Build Status, (*1)

FormObject is freely form library, (*2)

How to use it?


//Define Data class for Form class FooData extends \FormObject\Data { //Item's initializing value public $name = ''; public $email = ''; public function getFooSelect() { return array('itemA', 'itemB', 'itemC'); } } //Define Form class class FooForm extends \FormObject\Base { public function execute() { //validate //filtering //etc... return true; } } $data = new FooData; if ($_POST === array()) { //Views Input Form at first //use your template engine $views->context = $data; return $views; }else { //Submitted Form //pickup and overwrite values $data->bind($_POST); } //Form depends FormObject\Data $form = new FooForm($data); $form->execute(); //use your template engine $views->context = $form->getData(); return $views;

State Pattern?


//Define Data class FooData extends \FormObject\Data { public $state = 'init'; public $name = ''; public $hash = ''; } //Define State class FooValidate extends \FormObject\StateBase { protected $name = 'validate'; public function execute() { //You can use great Validation Libraries $this->getData()->state = $this->getName(); //Next State Class String or Instance return 'FooConfirm'; } } class FooConfirm extends \FormObject\StateBase { protected $name = 'confirm'; public function execute() { //insert CSRF Hash $data = $this->getData(); $data->state = $this->getName(); return ; } } class FooFinish extends \FormObject\StateBase { protected $name = 'finish'; public function execute() { //check CSRF //register data //send mail //logging $this->getData()->state = $this->getName(); return ; } } $data = new FooData(); $data->bind($_POST); switch ($data->state) { case 'input': $form = new FooValidate($data); //automatic switch state $dispatcher = new \FormObject\Dispatcher($form); $form = $dispatcher->dispatch(); break; case 'confirm': $form = new FooFinish($data); $form->execute(); redirect('form/finish.html'); break; default: $view->context = $data; return $view; } $view->context = $form->getData(); return $view;

The Versions

30/04 2016

dev-master

9999999-dev

Web Form Framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

form oop

02/12 2015

1.0.0

1.0.0.0

Web Form Framework

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

form oop