HosipLan

Untitled

Dec 18th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2.  
  3. namespace FrontModule\Forms\NewSurvey;
  4.  
  5. use Nette\Application\UI\Form,
  6.     Nette\InvalidStateException;
  7.  
  8. class NewQuestionForm extends Form
  9. {
  10.  
  11.     public function __construct()
  12.     {
  13.         parent::__construct();
  14.  
  15.         $this->getElementPrototype()->addClass('ajax');
  16.         $this->addProtection('Prosím odešlete formulář znovu (vypršela platnost bezpečnostního tokenu).');
  17.  
  18.         $this->addText('nameCopy', 'Název dotazníku:');
  19.  
  20.     $survey = $this->presenter->model->survey;
  21.     $questions = $this->addDynamic('questions', function ($question) use ($survey) {
  22.             $this->addTextArea('question', 'Otázka:', 50, 10)
  23.                     ->setRequired('Musíte vyplnit text otázky.');
  24.  
  25.             $this->addSelect('type', 'Typ:', array('0' => 'prvni', '1' => 'Druha'))
  26.                     ->setPrompt('-- Vyberte --');
  27.  
  28.             $this->addSelect('format', 'Formát otázky:', $survey->getSurveyPairs())
  29.                     ->setPrompt('-- Vyberte --');
  30.     });
  31.  
  32.     $questions->addSubmit('add', 'Přidat otázku');
  33.  
  34.         $this->onSuccess[] = array($this, 'submitted');
  35.     }
  36.  
  37.     public function submitted(Form $form)
  38.     {
  39.         try {
  40.             $values = $form->values;
  41.             var_dump($values);
  42.             exit;
  43.  
  44.             $this->presenter->redirect(':Front:NewSurvey:edit', array('id' => $survey));
  45.  
  46.         } catch (InvalidStateException $e) {
  47.             $this->presenter->flashMessage($e->getMessage(), 'warning');
  48.             $this->presenter->redirect('this');
  49.         }
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment