# Content

# Setup

composer require contributte/forms
1

# Application Form Factory

ApplicationFormFactory returns instance of Nette\Application\UI\Form. It should be used in place of StandaloneFormFactory if nette/application (opens new window) is installed.

extensions:
	forms.application: Contributte\Forms\DI\ApplicationFormFactoryExtension
1
2

You can override it by your implementation.

services:
	forms.application.factory: My\FormFactory
1
2

Straightforward way is to inject the factory in a presenter.

namespace App\Presenters;

use Contributte\Forms\IApplicationFormFactory;
use Nette\Application\UI\Form;

final class UserPresenter extends BasePresenter
{

	/** @var IApplicationFormFactory @inject */
	public $factory;

	protected function createComponentUserForm(): Form
	{
		$form = $this->factory->create();

		// Add inputs here!

		return $form;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Even better is to use the factory in your custom form factory.

namespace App\Forms;

use Contributte\Forms\IApplicationFormFactory;
use Nette\Application\UI\Form;

final class UserFormFactory
{

	/** @var IApplicationFormFactory */
	private $factory;

	public function __construct(IApplicationFormFactory $factory)
	{
		$this->factory = $factory;
	}

	public function create(): Form
	{
		$form = $this->factory->create();

		// Add inputs here!

		return $form;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# Standalone Form Factory

StandaloneFormFactory returns instance of Nette\Forms\Form. It should be used only if nette/application (opens new window) is not installed.

extensions:
	forms.standalone: Contributte\Forms\DI\StandaloneFormFactoryExtension
1
2

You can override it by your implementation.

services:
	forms.standalone.factory: My\FormFactory
1
2

Straightforward way is to inject factory in a presenter.

namespace App\Presenters;

use Contributte\Forms\IStandaloneFormFactory;
use Nette\Forms\Form;

final class UserPresenter extends BasePresenter
{

	/** @var IStandaloneFormFactory @inject */
	public $factory;

	protected function createComponentUserForm(): Form
	{
		$form = $this->factory->create();

		// Add inputs here!

		return $form;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Even better is to use the factory in your custom form factory.

namespace App\Forms;

use Contributte\Forms\IStandaloneFormFactory;
use Nette\Forms\Form;

final class UserFormFactory
{

	/** @var IStandaloneFormFactory */
	private $factory;

	public function __construct(IStandaloneFormFactory $factory)
	{
		$this->factory = $factory;
	}

	public function create(): Form
	{
		$form = $this->factory->create();

		// Add inputs here!

		return $form;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26