PHP code example of dcat-x / form-step

1. Go to this page and download the library: Download dcat-x/form-step library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dcat-x / form-step example snippets


use Dcat\Admin\Form;

$form = new Form(new User());

$form->multipleSteps(function ($step) {
    // 第一步:基本信息
    $step->add('基本信息', function ($form) {
        $form->text('name', '姓名')->orm->text('phone', '电话');
        $form->textarea('address', '地址');
    });

    // 第三步:确认信息
    $step->add('确认', function ($form) {
        $form->textarea('remarks', '备注');
    });
});

return $form;

$form->multipleSteps(function ($step) {
    // 添加步骤...

    // 设置容器宽度
    $step->width('1200px');

    // 设置内边距
    $step->padding('30px 20px');

    // 启用数据记忆(刷新页面不丢失)
    $step->remember(true);

    // 选择初始步骤
    $step->select(0);
});

$form->multipleSteps(function ($step) {
    // 添加步骤...

    // 自定义完成页面
    $step->done('完成', function ($page) {
        $data = $page->input(); // 获取所有输入数据
        $id = $page->getNewId(); // 获取新创建的记录 ID

        return view('my-completion-page', compact('data', 'id'));
    });
});

$form->multipleSteps(function ($step) {
    $step->add('步骤一', function ($form) {
        $form->text('name');

        // 离开当前步骤时执行
        $form->leaving('console.log("离开步骤一")');

        // 显示当前步骤时执行
        $form->shown('console.log("显示步骤一")');
    });
});

// 全局事件
$step->leaving('console.log("离开步骤", args.index)');
$step->shown('console.log("显示步骤", args.index)');

$step->add('基本信息', function ($form) {
    $form->setDescription('请填写您的基本信息');

    $form->text('name');
    $form->email('email');
});
bash
php artisan vendor:publish --provider="Dcat\Admin\FormStep\FormStepServiceProvider"