Advertisement
nanuqcz

Nette dynamic form [bad practise]

Mar 3rd, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. use Nette\Application\UI\Form,
  3.     Nette\Forms\Controls\SubmitButton;
  4.  
  5. /**
  6.  * Homepage presenter.
  7.  *
  8.  * @author     John Doe
  9.  * @package    MyApplication
  10.  */
  11. class HomepagePresenter extends BasePresenter
  12. {
  13.  
  14.     public function renderDefault()
  15.     {
  16.         $this->template->anyVariable = 'any value';
  17.     }
  18.  
  19.  
  20.  
  21.     protected function createComponentTestForm()
  22.     {
  23.         $form = new Form();
  24.         $form->addSelect('item', 'Položka', array(1 => 'Foo', 2 => 'Bar', 3 => 'Baz'));
  25.         $form->addSubmit('send', 'Odeslat')
  26.             ->onClick[] = callback($this, 'addSubitemToForm');
  27.  
  28.         return $form;
  29.     }
  30.  
  31.     public function addSubitemToForm(SubmitButton $button)
  32.     {
  33.         $this['testForm']->addSelect('subitem', 'Pod-položky', array(1 => 'Subfoo', 2 => 'Subbar', 3 => 'Subbaz'));
  34.         $this['testForm']->addSubmit('delete', 'Smaž')
  35.             ->onClick[] = callback($this, 'deleteSubitem');
  36.     }
  37.  
  38.     public function deleteSubitem(SubmitButton $button)
  39.     {
  40.         dump("Jsem zde, už stačí jen smazat co potřebuji a redirectnout.");
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement