$form->onSuccess[] function not executed in Nette 2.2.6

Notice: This thread is very old.
OKweb
Member | 12
+
0
-

I updated from Nette 2.2.3 to 2.2.6 and it looks like the function I set in $form->onSuccess[] is not executed, only link from $form->setAction() is opened.

This worked in Nette 2.2.3:

<?php
    protected function createComponentProduktForm()
    {
        $form = new Nette\Application\UI\Form;
        $polozky = array();
        foreach ($this->database->table('avg_katalog') as $polozka)
            $polozky[$polozka->id] = $polozka->id;
        $form->addRadioList('polozka', 'Položka:', $polozky)->setRequired('Vyberte, prosím, položku, ktorú chcete pridať do košíka.');
        $form->addSubmit('pridat', 'Pridať do košíka');
        $form->setAction($this->link('Product:default', array('slug' => $this->getParameter('slug'))));
        $form->onSuccess[] = $this->produktFormSucceeded;
        return $form;
    }

    public function produktFormSucceeded($form)
    {
        $values = $form->getValues();
        $polozka = $values->polozka;
        $nakupnyKosik = $this->getSession('nakupnyKosik');
        if (isset($nakupnyKosik->polozky[$polozka]))
            $nakupnyKosik->polozky[$polozka]++;
        else
            $nakupnyKosik->polozky[$polozka] = 1;
    }
?>
Casper
Member | 253
+
+1
-

It is caused by this commit, see related threads and original issue.

Ugly solution should be:

$form->setAction($this->link('Product:default', array(
    'slug' => $this->getParameter('slug'),
    'do' => 'produktForm-submit' // or use $name passed to createComponent* method instead of produktForm
)));

Last edited by Casper (2014-11-19 15:41)

David Grudl
Nette Core | 8218
+
0
-

It is nice solution.

Casper
Member | 253
+
0
-

@DavidGrudl Well, better is to use $name.Form::NAME_SEPARATOR.'submit', but I still don't like the hardcoded “submit” word. IMHO, it should be defined as constant too. What do you think?

Last edited by Casper (2014-11-19 17:09)

OKweb
Member | 12
+
0
-

Casper wrote:

It is caused by this commit, see related threads and original issue.

Ugly solution should be:

$form->setAction($this->link('Product:default', array(
    'slug' => $this->getParameter('slug'),
    'do' => 'produktForm-submit' // or use $name passed to createComponent* method instead of produktForm
)));

Thanks! It is helpful.