Mistrfilda / forms-wizard

:tophat: Easy to use step-by-step form for Nette Framework

Home Page:https://contributte.org/packages/contributte/forms-wizard.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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>

About

:tophat: Easy to use step-by-step form for Nette Framework

https://contributte.org/packages/contributte/forms-wizard.html


Languages

Language:PHP 99.6%Language:HTML 0.4%