Adding multiple components with form

Notice: This thread is very old.
Member | 21

I have page with components corresponding to database rows. Every component also contains form. All the forms however have id frm-component-form and same name attributes so when I send one form, the first form thinks it was submitted.

class Component extends Nette\Application\UI\Control {
	private $id;

	public function render($id) {
		$this->id = $id;
		$this->template->setFile(__DIR__ . '/component.latte');

	public function createComponentForm() {
		$form = new Nette\Application\UI\Form;
		$form->addHidden('id', $this->id);
		$form->addText('text', 'Text:');
		$form->addSubmit('send', 'Send');
		$form->onSubmit[] = function(Nette\Forms\Form $form) {

		return $form;

public function createComponentComponent() {
	return new Component;
{control component, 1}
{control component, 2}

When I try to initialise new Nette\Application\UI\Form(null, 'component'.$this->id) nothing is different until I change Nette\Application\UI\Form to pass $name to Nette\Forms\Form but this only affects the form, not any inputs.

Another problem is that the Form seems to be created only once so it always has id of 1.

How can I pass data to component and make it possible for multiple forms to be on the same page?

Last edited by prebijak (2014-09-20 21:55)

Backer | 404

use, multiplier. Article is Czech only but I think you will understand the code (it is easy)