1. Go to this page and download the library: Download junkins/multi-step-form 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/ */
junkins / multi-step-form example snippets
namespace App\View;
use Cake\View\View;
class AppView extends View
{
/**
* initialize
*/
public function initialize()
{
// AppFormHelperの読み込み設定
$this->loadHelper('Form', [
'className' => 'AppForm',
]);
}
}
namespace App\Controller;
use MultiStepForm\Controller\Traits\MultiStepFormTrait;
/**
* TopicsController
*/
class TopicsController extends Controller
{
use MultiStepFormTrait;
/**
* initialize
*/
public function initialize()
{
parent::initialize();
// 通常のアクションとしてアクセスが必要な場合は whitelist に設定する
$this->loadComponent('MultiStepForm.MultiStepForm', [
'whitelist' => [
'index',
'view',
'add',
'edit',
'delete'
]
]);
}
/**
* add
*/
public function add()
{
$this->MultiStepForm->dispatch();
}
/**
* add_input
*/
public function add_input()
{
$topic = $this->MultiStepForm->getEntity();
$this->set(compact('topic'));
$this->render('add_input');
}
/**
* add_confirm
*/
public function add_confirm()
{
$topic = $this->MultiStepForm->getEntity();
$this->set(compact('topic'));
$this->render('add_confirm');
}
/**
* add_finish
*/
public function add_finish()
{
$data = $this->MultiStepForm->getData();
$topic = $this->Topics->newEntity($data);
if($this->Topics->save($topic)){
$this->Flash->success('Success!');
} else {
$this->Flash->error('Error!');
}
$this->redirect(['action' => 'index']);
}
}