Code Monkey home page Code Monkey logo

yii2-wizard's Introduction

yii2-wizard

Yii2 Extension to handle multi-form wizards.

Features

  • All forms submit to the same route - user friendly URLs
  • Next/Previous or Forward Only navigation - registration forms will probably use Next/Previous navigation; tests will probably use Forward Only
  • Looping - repeat one or more steps on a form as many times as needed
  • Plot Branching Navigation (PBN) - allows the form to decide which path to take depending on a user's response to questions
  • Step timeout - steps can have a timeout to ensure a user responds within a given time
  • Save/Restore - save partially completed forms then restore and continue from that point later
  • Event driven - write the handler functions and hook them up to events

For license information see the LICENSE-file.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist beastbytes/yii2-wizard

or add

"beastbytes/yii2-wizard": "*"

to the require section of your composer.json.

Usage

Below is a very short overview of how to use the extension; the examples folder shows how to implement PBN, looping, forward only navigation, and step timeout in examples of a quiz, survey, and registration.

Attach WizardBehavior to a controller.

The controller contains the event handlers; the two most important events are WizardBehavior::EVENT_WIZARD_STEP and WizardBehavior::EVENT_AFTER_WIZARD, these are responsible for handling the steps of the wizard and processing the data at the end of the wizard respectively.

Controller Action

The controller action is very simple:

public function actionWizard($step = null)
{
    return $this->step($step);
}

WizardBehavior::EVENT_WIZARD_STEP

This event's handler is responsible for validating submitted data and deciding in what direction the Wizard should proceed; this and the data to be stored is placed into the event. When the event is marked as handled by handler the wizard will take the appropriate action.

WizardBehavior::EVENT_AFTER_WIZARD

The handler for this event is responsible for taking the required action once the Wizard has completed; this could be rendering a page based on the user input and/or saving the data to persistant storage.

yii2-wizard's People

Contributors

beastbytes avatar freezy-sk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-wizard's Issues

Demo

great job on this do you have a demo for this

I use example, but return empty page

I use example, but return empty page


   public function quizWizardStep($event)
    {
        $modelName = 'app\models\wizard\quiz\Question';
        $model = new $modelName(['question' => $this->questions[$event->n]]);
        $t = count($this->questions);
        debug($model);
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            $event->data     = $model;
            $event->nextStep = ($event->n < $t - 1
                ? WizardBehavior::DIRECTION_REPEAT
                : WizardBehavior::DIRECTION_FORWARD
            );
            $event->handled  = true;
        } else {
          
            $event->data = $this->render('quiz\question', compact('event', 'model', 't'));
              
        }
        
      
    }
    public function actionQuiz($step = null)
    {
        //if ($step===null) $this->resetWizard();
        return $this->step($step);
    }

perhaps the page does not return if to output a variable $event->data , it contains the page code

small error on WizardBehaviour.php with php.ini error_reporting = E_ALL

The line 273 of WizardBehaviour generate error when error_reporting in php.ini set to E_ALL. Undefined variable $step.

if (isset($this->_session[$this->_stepDataKey][$step][$this->_session[$this->_indexKey]])) {
$event->stepData = $this->_session[$this->_stepDataKey][$step][$this->_session[$this->_indexKey]];
}

Changing to

if (isset($this->_session[$this->_stepDataKey][$step]) && isset($this->_session[$this->_stepDataKey][$step][$this->_session[$this->_indexKey]])) {
$event->stepData = $this->_session[$this->_stepDataKey][$step][$this->_session[$this->_indexKey]];
}

solve my troubles.

Previous Event Model

Hi, thanks for writing this extension. I'm having trouble obtaining a previous event model. I want to obtain a previous event model during one of the following events.. I've tried using $event->sender->read(), but this is all Private Data constructs.. Is there an easier way to do this than writing the data to a file like in your example for the registration? I realize I can add the model to my own session variable during the registerWizardStep function, but I don't see the need to increase the session storage.. Is there an easier way?

How to create survey dinamicly?

I need to make a surveys which would be generated by for example SurveyQuestion model records wich are related to Survey model.

yii2-wizard von Yeti not running and no friendly urls

H!
Thanks for adapting your popular extension to Yii2

I have not been able to get this extension to work .
I have done everything I could do like the examples suggest, particularly the registration example but yet I have these problemes:

1) I cannot even run step 1 of my forms. I get the following error:

  PHP Notice ā€“ yii\base\ErrorException 
Undefined index: stepone
.
(stepone is the name of my first step) and the wizard stops at this line:
  if (isset($this->_session[$this->_stepDataKey][$step][$this->_session[$this->_indexKey]])) {
                $event->stepData = $this->_session[$this->_stepDataKey][$step][$this->_session[$this->_indexKey]];
            }
.


It is line nĀ° 273 of the WizardBehavior.

2) Also, the url it shows is:
.../submission?step=stepone
(submission is my action) which is very far from beeing a pretty Url.

What am I doing wrong?
Can please someone help me?

Author widget idiot.

Author widget idiot.
Your expansion, even from the example that is available in source code does not work ?? This example is written as a widget fuck.

how to change the stepName ?

controller code

            $config = [
                'steps' => ['profile', 'region', 'photo'],
                'events' => [
                    WizardBehavior::EVENT_WIZARD_STEP => [$this, $action->id.'WizardStep'], 
                    WizardBehavior::EVENT_AFTER_WIZARD => [$this, $action->id.'AfterWizard'], 
                    WizardBehavior::EVENT_INVALID_STEP => [$this, 'invalidStep'],
                ]
            ];
            $config['class'] = WizardBehavior::className();
            $this->attachBehavior('wizard', $config);

view code

<?= WizardMenu::widget( .............. ); ?>

I want to design an I18N site , So I need to change step's label name to other language in the view , but step's key name needn't change , how to do it ?

Saving stepData on Session - issues

Hi, thanks for your extension, it's really nice.

I have experienced some issues in the "saveStep" function and I thought I would share it with everyone.
Basically I have noticed that the data stored in the session was not always updating when submitting the forms.
I've had to unset the variable in the session before updating the data, as you can see below:

WizardBehavior.php

protected function saveStep($step, $data)
    {
        if (!isset($this->_session[$this->_stepDataKey][$step])) {
            $this->_session[$this->_stepDataKey][$step] = new \ArrayObject;
        }
        unset($this->_session[$this->_stepDataKey][$step]);
        $this->_session[$this->_stepDataKey][$step][] = $data;
    }

After this update things seems working fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.