Skip to content
🎩 Easy to use step-by-step form for Nette Framework
Branch: master
Clone or download
Latest commit 7e0db8a Jul 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src final values are cached Jun 5, 2019
tests final values are cached Jun 5, 2019
.gitignore
.travis.yml contributte Feb 21, 2019
README.md
codeception.yml Initial commit Jul 27, 2015
composer.json Add master alias Jul 9, 2019
ruleset.xml

README.md

nette/forms wizard

Build Status

Installation

Composer

composer require contributte/forms-wizard

Config

extensions:
    - Contributte\FormWizard\DI\WizardExtension

Usage

Component


use Nette\Application\UI\Form;

class Wizard extends Contribute\FormWizard\Wizard {

    protected function finish(): void 
    {
        $values = $this->getValues();
    }

    protected function createStep1(): Form 
    {
        $form = $this->createForm();

        $form->addText('name', 'User name')
            ->setRequired();

        $form->addSubmit(self::NEXT_SUBMIT_NAME, 'Next');

        return $form;
    }

    protected function createStep2(): Form 
    {
        $form = $this->createForm();

        $form->addText('email', 'Email')
            ->setRequired();

        $form->addSubmit(self::PREV_SUBMIT_NAME, 'Back');
        $form->addSubmit(self::FINISH_SUBMIT_NAME, 'Register');

        return $form;
    }
}
services:
    - Wizard

Presenter


final class HomepagePresenter extends Nette\Application\UI\Presenter {

    /** @var Wizard @inject */
    public $wizard;
    
    public function handleChangeStep(int $step): void 
    {    
        $this['wizard']->setStep($step);
        
        $this->redirect('wizard'); // Optional, hides parameter from URL
    }

    protected function createComponentWizard(): Wizard 
    {
        return $this->wizard;
    }

}

Template

<div n:wizard="wizard">
    <ul n:if="!$wizard->isSuccess()">
        <li n:foreach="$wizard->steps as $step" n:class="$wizard->isDisabled($step) ? disabled, $wizard->isActive($step) ? active">
            <a n:tag-if="$wizard->useLink($step)" n:href="changeStep! $step">{$step}</a>
        </li>
    </ul>

    {step 1}
        {control $form}
    {/step}

    {step 2}
        {control $form}
    {/step}

    {step success}
        Registration was successful
    {/step}
</div>
You can’t perform that action at this time.