Formular se neodesila (prazdny attribut action)

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Elijen
Člen | 171
+
0
-

Zdravim, vim ze se tu toto tema jiz resilo, ale rady z ostatnich vlaken jsem zkousel. V presenteru vytvarim formular nasledovne:

public function createComponentFilterTableForm()
    {
        $categories = array("Category 1", "Category 2", "Category 3", "Category 4", "Category 5", "Category 6", "Category 7");

        $form = new AppForm($this, 'filterTableForm');

        $renderer = $form->getRenderer();
        $renderer->wrappers['control']['container'] = NULL;
        $renderer->wrappers['pair']['container'] = NULL;
        $renderer->wrappers['label']['container'] = NULL;
        $renderer->wrappers['group']['container'] = "tr";
        $renderer->wrappers['controls']['container'] = NULL;
        $renderer->wrappers['form']['container'] = 'table class="filter-table"';

        $c=0;
        foreach($categories as $id => $caption)
        {
            //If this is 4th control make a new row
            if($c == 0)
                $form->AddGroup();

            $form->AddCheckbox("cat$id", $caption);


            $c = ($c+1) % 3;
        }

        if($c == 0)
            $form->AddGroup();

        $i_tag = Html::el("i");
        $i_tag->setText(_("Uncategorized"));
        $form->AddCheckbox("uncategorized", $i_tag);
        $c = ($c+1) % 3;

        //New row
        $form->AddGroup();
        $i_tag = Html::el("i");
        $i_tag->setText(_("All"));
        $form->AddCheckbox("all", $i_tag);

        //New row
        $form->AddGroup();
        $form->AddSubmit('search', _('Search'));
    }

zkousel jsem i variantu:

public function createComponentFilterTableForm()
{
	$form = new AppForm;
	[...]
	return $form;
}

v sablone presenteru mam:

{block content}
<h1>{$header}</h1>
{widget filterTableForm}
{ifset $result}{widget resultTable}{/if}

Nicmene formular se generuje s action="#" a po jeho odeslani se nic nedeje. (metoda formSubmitted se nezavola). V cem by mohl byt problem?

Diky ;)

Editoval Elijen (1. 9. 2010 12:02)

Aurielle
Člen | 1281
+
0
-

Odkaz s # znamená chybu v jeho generování, tzn. něco typu chybějící presenter nebo routa. Když zapneš dev mód, tak se ti chyba ukáže právě místo #.

Elijen
Člen | 171
+
0
-

V bootstrapu Debug::enable(Debug::DEVELOPMENT); mam, tedy by dev mod zapnuty byt mel. Nebo ne?

Editoval Elijen (1. 9. 2010 12:15)

natrim
Člen | 73
+
0
-

Vyzkoušel jsi toto?

<?php
protected function createComponentFilterTableForm($name) {
$form = new AppForm($this, $name);

// ...
// ...
// ...
// ...
// form .)

$form->onSubmit[] = callback($this,'filterTableFormSubmit');

return $form;
}

public function filterTableFormSubmit(AppForm $form){
//co ces udelat .)

}
?>

Editoval natrim (1. 9. 2010 15:59)

Elijen
Člen | 171
+
0
-

Tak problem je na 100% v routovani. AppForm nepreda konstruktoru objektu parametr ‚type‘.

V presenteru:

echo $this->link($this->getName().':'.$this->getAction(), array()); // '#'
echo $this->link($this->getName().':'.$this->getAction(), array('type' => 'books')); // '/books'

Takhle vypadaji routy:

$router[] = new Route('[index.php]', array(
	'presenter' => 'Homepage',
	'action' => 'default',
));

$router[] = new Route('[<admin admin>/]<type texts|books|documents|about>/<id>', array(
    'presenter' => 'Articles',
    'action' => 'show',
));

$router[] = new Route('[<admin admin>/]<type about>', array(
    'presenter' => 'Articles',
    'action' => 'show',
));

$router[] = new Route('[<admin admin>/]<type texts|books|documents>', array(
    'presenter' => 'Articles',
    'action' => 'search',
));

Ted je otazka, jak to opravit tak, aby routy zustali funkcne stejne?

EDIT
Prijde mi, ze v metude attached tridy AppForm je bug.

protected function attached($presenter)
{
	if ($presenter instanceof Presenter) {
		$name = $this->lookupPath('Presenter');
			if (!isset($this->getElementPrototype()->id)) {
			$this->getElementPrototype()->id = 'frm-' . $name;
		}
			$this->setAction(new Link(
			$presenter,
			$name . self::NAME_SEPARATOR . 'submit!',
			array() // <======== melo by byt $presenter->getParam()
		));
			// fill-in the form with HTTP data
		if ($this->isSubmitted()) {
			foreach ($this->getControls() as $control) {
				$control->loadHttpData();
			}
		}
	}
parent::attached($presenter);
}

Pokud to upravim, formular zacne fungovat.

Editoval Elijen (1. 9. 2010 17:27)