定制 infinityloop-dev/multistep-form 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

infinityloop-dev/multistep-form

Composer 安装命令:

composer require infinityloop-dev/multistep-form

包简介

Component for Nette framwork which helps with creation of multistep forms.

README 文档

README

🔧 Component for Nette framwork which helps with creation of multistep forms.

Introduction

This component provides a simple way to create a multistep form. Handles swapping between steps, passing values from previous steps to current one and passing all combined values to final success callback. Also handles common edge cases, such as distinction between multiple instances of one form accessed by one client.

Installation

Install package using composer

composer require infinityloop-dev/multistep-form

Dependencies

How to use

  • Register \Infinityloop\MultistepForm\IMultiStepFormFactory as service in cofiguration file.
  • Inject it into component/presenter where you wish to use multi step form,
    • write createComponent method and use macro {control} in template file
  • Submit buttons for moving forward and backward are added automaticaly.

Example createComponent method

protected function createComponentMultistepForm() : \Infinityloop\MultistepForm\MultistepForm
{
    $multistepForm = $this->multistepFormFactory->create()
        ->setDefaults(['action' => \App\Enum\EAction::ACTION2])
        ->setSuccessCallback(function(array $values) {
            $this->model->save($values);
        });

    // first step
    $multistepForm->addFactory(function() : \Nette\Forms\Form {
        $form = new \Nette\Application\UI\Form();
        $form->addProtection();
        $form->setTranslator($this->translator);

        $form->addSelect('action', 'Akce', \App\Enum\EAction::ENUM)
            ->setRequired();

        return $form;
    }, __DIR__ . '/step1.latte');

    // second step
    $multistepForm->addFactory(function(array $previousValues) : \Nette\Forms\Form {
        $form = new \Nette\Application\UI\Form();
        $form->addProtection();
        $form->setTranslator($this->translator);

        if (\in_array($previousValues['action'], [\App\Enum\EAction::ACTION1, \App\Enum\EAction::ACTION2], true)) {
            $form->addText('action_1or2', 'Action 1 or 2')
                ->setRequired();
        } else {
            $form->addText('action_xyz', 'Action Xyz')
                ->setRequired();
        }
    });

    return $multistepForm;
}

Options

  • setDefaults(array)
    • default values for your form, all steps at once
  • addFactory(callable, ?string)
    • first argument is factory function from which the form is created
    • second argument is custom template path
      • the standard {control form} is used if no template is specified for current step
      • in custom template you can manualy render each step using {form form} ... {/form}
  • setSuccessCallback(callable)
    • callback where values from all steps are sent after submitting last step

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固