承接 reioto/form-object 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

reioto/form-object

Composer 安装命令:

composer require reioto/form-object

包简介

Web Form Framework

关键字:

README 文档

README

Build Status

FormObject is freely form library

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;

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-12-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固