示例#1
0
      $form->addSubmit('cancel', 'Cancel')->setAttribute('class', 'btn btn-default')->setValidationScope([]);
      return $form;
  }
  /** Vlastná validácia pre AddUserForm
 * @param Nette\Application\UI\Form $button
 */
  public function validateAddUserForm($button)
  {
      $values = $button->getForm()->getValues();
      if ($button->isSubmitted()->name == 'uloz') {
          // Over, ci dane username uz existuje.
          if ($this->users->findBy(['username' => $values->username])->count() > 0) {
              $button->addError(sprintf('Zadané užívateľské meno %s už existuje! Zvolte prosím iné!', $values->username));
          }
          // Over, ci dany email uz existuje.
示例#2
0
 public function formSucceeded(Form $form, $values)
 {
     if ($values->remember) {
         $this->user->setExpiration('14 days', FALSE);
     } else {
         $this->user->setExpiration('20 minutes', TRUE);
     }
     if ($form->isSubmitted()->getName() != 'cancel') {
         try {
             $this->user->login($values->username, $values->password);
         } catch (Nette\Security\AuthenticationException $e) {
             $form->addError($e->getMessage());
         }
     }
 }
示例#3
0
          $form->addText('rok', 'Rok narodenia:', 4, 5)->addRule(Form::RANGE, 'Rok narodenia musí byť v rozsahu od %d do %d', [1900, StrFTime("%Y", Time())]);
      }
      if ($user_view_fields["telefon"]) {
          $form->addText('telefon', 'Telefón:', 20, 20);
      }
      if ($user_view_fields["poznamka"]) {
          $form->addText('poznamka', 'Poznámka:', 50, 250);
      }
      if ($user_view_fields["pohl"]) {
          $form->addSelect('pohl', 'Pohlavie:', ['M' => 'Muž', 'Z' => 'Žena']);
      }
      $form->onValidate[] = [$this, 'validateEditUserForm'];
      $form->addSubmit('uloz', 'Ulož')->setAttribute('class', 'btn btn-success')->onClick[] = [$this, 'editUserFormSubmitted'];
      $form->addSubmit('cancel', 'Cancel')->setAttribute('class', 'btn btn-default')->setValidationScope(FALSE);
      return $form;
  }
  /** Vlastná validácia
 * @param Nette\Application\UI\Form $button
示例#4
0
 public function processImageForm(Form $form)
 {
     // uklada fotky
     if ($form->isSubmitted()) {
         $uploaded = 0;
         $dirPath = $this->dirPath;
         for ($i = 1; $i <= $this->uploadCount; $i++) {
             $file = $form['file' . $i]->getValue();
             if (empty($file)) {
                 $this->flashMessage('Nebyl vybrán žádný soubor nebo byl datově příliš velký.', 'warning');
             } elseif ($file->isOK()) {
                 if ($file->getContentType() == 'image/jpeg' || $file->getContentType() == 'image/jpg' || $file->getContentType() == 'image/png') {
                     $tmp = WWW_DIR . '/images/tmp/img.jpg';
                     $file->move($tmp);
                     $filename = $this->uploadingHelper();
                     $image = Image::fromFile($tmp);
                     if ($this->imageSizes['x']) {
                         $image->resize($this->imageSizes['x'], $this->imageSizes['y'], Image::SHRINK_ONLY);
                     }
                     $image->save($dirPath . $filename, 85, Image::JPEG);
                     $imageBig = Image::fromFile($tmp);
                     if ($this->imageSizes['xBig']) {
                         $imageBig->resize($this->imageSizes['xBig'], $this->imageSizes['yBig'], Image::SHRINK_ONLY);
                     }
                     $imageBig->save($dirPath . 'big/' . $filename, 85, Image::JPEG);
                     $uploaded++;
                 } else {
                     $this->flashMessage('Soubor není v požadovaném formátu.', 'warning');
                 }
             }
         }
     }
     if ($uploaded > 0) {
         $this->flashMessage($uploaded . ' obrázků bylo úspěšně nahráno.', 'success');
     } else {
         $this->flashMessage('Nahráno 0 souborů.');
     }
     $this->redirect('this');
 }
示例#5
0
 public function processFeedbackWebForm(Form $form)
 {
     if ($form->isSubmitted()) {
         $values = $form->getValues();
         $values['added'] = new \DateTime();
         unset($values['spam']);
         unset($values['form_created']);
         // vlozime do DB
         $this->feedback->create($values);
         if ($this->lang == 'cs') {
             $this->flashMessage('Děkujeme za to, že pomáháte vylepšit český webový archiv', 'success');
         } else {
             $this->flashMessage('Thank you for your feedback!', 'success');
         }
     }
     $this->redirect('this');
 }
示例#6
0
 /**
  * FilterAndGroupAction form factory
  * @return Form
  */
 public function createComponentFilter()
 {
     $form = new Form($this, 'filter');
     $form->setMethod(static::$form_method);
     $form->setTranslator($this->getTranslator());
     /**
      * InlineEdit part
      */
     $inline_edit_container = $form->addContainer('inline_edit');
     if ($this->inlineEdit instanceof InlineEdit) {
         $inline_edit_container->addSubmit('submit', 'ublaboo_datagrid.save');
         $inline_edit_container->addSubmit('cancel', 'ublaboo_datagrid.cancel')->setValidationScope(FALSE);
         $this->inlineEdit->onControlAdd($inline_edit_container);
         $this->inlineEdit->onControlAfterAdd($inline_edit_container);
     }
     /**
      * InlineAdd part
      */
     $inline_add_container = $form->addContainer('inline_add');
     if ($this->inlineAdd instanceof InlineEdit) {
         $inline_add_container->addSubmit('submit', 'ublaboo_datagrid.save');
         $inline_add_container->addSubmit('cancel', 'ublaboo_datagrid.cancel')->setValidationScope(FALSE)->setAttribute('data-datagrid-cancel-inline-add', TRUE);
         $this->inlineAdd->onControlAdd($inline_add_container);
         $this->inlineAdd->onControlAfterAdd($inline_add_container);
     }
     /**
      * ItemDetail form part
      */
     $items_detail_form = $this->getItemDetailForm();
     if ($items_detail_form instanceof Nette\Forms\Container) {
         $form['items_detail_form'] = $items_detail_form;
     }
     /**
      * Filter part
      */
     $filter_container = $form->addContainer('filter');
     foreach ($this->filters as $filter) {
         $filter->addToFormContainer($filter_container);
     }
     if (!$this->hasAutoSubmit()) {
         $filter_container['submit'] = $this->getFilterSubmitButton();
     }
     /**
      * Group action part
      */
     $group_action_container = $form->addContainer('group_action');
     if ($this->hasGroupActions()) {
         $this->getGroupActionCollection()->addToFormContainer($group_action_container);
     }
     if (!$form->isSubmitted()) {
         $this->setFilterContainerDefaults($form['filter'], $this->filter);
     }
     /**
      * Per page part
      */
     $form->addSelect('per_page', '', $this->getItemsPerPageList())->setTranslator(NULL);
     if (!$form->isSubmitted()) {
         $form['per_page']->setValue($this->getPerPage());
     }
     $form->addSubmit('per_page_submit', 'ublaboo_datagrid.per_page_submit');
     $form->onSubmit[] = [$this, 'filterSucceeded'];
 }
示例#7
0
文件: AdminGrid.php 项目: venne/venne
 public function formSuccess(\Nette\Application\UI\Form $form)
 {
     if (isset($form['_submit']) && $form->isSubmitted() === $form['_submit']) {
         if ($this->mode === self::MODE_PLACE) {
             $this->redrawControl('formContainer');
         }
         $this->redirect('this', array('formName' => null, 'id' => null, 'mode' => null));
         $this->redrawControl('table');
     }
 }
示例#8
0
 public function formSuccess(Form $form)
 {
     $values = $form->getValues();
     $button = $form->isSubmitted();
     if ($values->remember) {
         $form->presenter->user->setExpiration('+ 14 days', false);
     } else {
         $form->presenter->user->setExpiration('+ 20 minutes', true);
     }
     if ($button === $form['_submit']) {
         try {
             $form->presenter->user->login($values->username, $values->password);
         } catch (AuthenticationException $e) {
             $this->onError($this, $e->getMessage());
         }
     } else {
         $this->redirect('login!', str_replace('_', ' ', $button->name));
     }
     $this->onSuccess($this);
     $this->redirect('this');
 }
示例#9
0
文件: DataGrid.php 项目: lohini/cf
 /**
  * Data grid form submit handler
  *
  * @param \Nette\Application\UI\Form $form
  * @throws \Nette\InvalidStateException
  */
 public function formSubmitHandler(\Nette\Application\UI\Form $form)
 {
     $this->receivedSignal = 'submit';
     // was form submitted?
     if ($form->isSubmitted()) {
         $values = $form->getValues();
         if ($form['filterSubmit']->isSubmittedBy()) {
             $this->handleFilter($values['filters']);
         } elseif ($form['pageSubmit']->isSubmittedBy()) {
             $this->handlePage($values['page']);
         } elseif ($form['itemsSubmit']->isSubmittedBy()) {
             $this->handleItems($values['items']);
         } elseif ($form['resetSubmit']->isSubmittedBy()) {
             $this->handleReset();
         } elseif ($form['operationSubmit']->isSubmittedBy()) {
             if (!is_array($this->onOperationSubmit)) {
                 throw new \Nette\InvalidStateException('No user defined handler for operations; assign valid callback to operations handler into Lohini\\Components\\DataGrid\\DataGrid::$operationsHandler variable.');
             }
         } else {
             throw new \Nette\InvalidStateException('Unknown submit button.');
         }
     }
     $this->finalize();
 }
 public function processTopicCollectionForm(Form $form)
 {
     $id = (int) $this->getParam('id');
     $suffix = "";
     if ($form->isSubmitted()) {
         $values = $form->getValues();
         // pokud bylo odeslano pomoci 'ulozit a publikovat', rovnou se to publikuje
         if (isset($form['saveAndPublish']) && $form['saveAndPublish']->isSubmittedBy()) {
             $values['active'] = TRUE;
             $suffix = " a publikována";
         }
         // ukladani nebo editace
         if ($id > 0) {
             // edit
             $topicCollection = $this->topicCollections->find($id);
             $topicCollection->update($values);
         } else {
             // add
             $topicCollection = $this->topicCollections->create($values);
             $topicCollection->update(array('order_num' => $topicCollection->id));
         }
         $this->flashMessage('Sbírka byla uložena' . $suffix . '.', 'success');
         //$this->redirect('edit',  array('id'=>$topicCollection->id));
     }
     $this->redirect('TopicCollections:');
 }
示例#11
0
 public function processHomepageNewForm(Form $form)
 {
     $id = (int) $this->getParam('id');
     $suffix = "";
     if ($form->isSubmitted()) {
         $values = $form->getValues();
         // pokud bylo odeslano pomoci 'ulozit a publikovat', rovnou se to publikuje
         if (isset($form['saveAndPublish']) && $form['saveAndPublish']->isSubmittedBy()) {
             $values['active'] = TRUE;
             $suffix = " a publikována";
         }
         // ukladani nebo editace
         if ($id > 0) {
             // edit
             $homepageNew = $this->homepageNews->find($id);
             $homepageNew->update($values);
         } else {
             // add
             $homepageNew = $this->homepageNews->create($values);
             $homepageNew->update(array('added' => new \DateTime(), 'order_num' => $homepageNew->id));
         }
         $this->flashMessage('Novinka byla uložena' . $suffix . '.', 'success');
         $this->redirect('edit', array('id' => $homepageNew->id));
     }
     $this->redirect('HomepageNews:');
 }
 public function processSelectedResourceForm(Form $form)
 {
     $id = (int) $this->getParam('id');
     $suffix = "";
     if ($form->isSubmitted()) {
         $values = $form->getValues();
         // pokud bylo odeslano pomoci 'ulozit a publikovat', rovnou se to publikuje
         if (isset($form['saveAndPublish']) && $form['saveAndPublish']->isSubmittedBy()) {
             $values['active'] = TRUE;
             $suffix = " a publikován";
         }
         // nacteme si potrebne zaznamy z databaze
         $selectedResource = $this->selectedResources->find($id);
         $originalKeywords = $this->keywordsResources->findBy(array('resource_id' => $selectedResource->resource_id));
         // projdeme vsechny originalni klicova slova ke zdroji a ty co se shoduji s vybranymi, dame do pole
         $selectedKeywords = array();
         foreach ($originalKeywords as $ok) {
             if ($values['keyword_' . $ok->id] == TRUE) {
                 $selectedKeywords[] = $ok->id;
             }
             unset($values['keyword_' . $ok->id]);
             // at se to nesnazi ulozit do db
         }
         $values['keywords'] = implode(',', $selectedKeywords);
         $selectedResource->update($values);
         $this->flashMessage('Výběr zdroje byl uložen' . $suffix . '.', 'success');
         //$this->redirect('edit',  array('id'=>$selectedResource->id));
     }
     $this->redirect('SelectedResources:');
 }
示例#13
0
 public function createComponentAdjustOrderForm($name)
 {
     vBuilder\Application\UI\Form\IntegerPicker::register();
     $form = new Form($this, $name);
     $form->addHidden('ids');
     if ($form->isSubmitted()) {
         $this->setProductIds(explode(',', $form->values->ids));
     } else {
         $form['ids']->setDefaultValue(implode(',', $this->getProductIds()));
     }
     foreach ($this->products as $product) {
         $form->addIntegerPicker('amount' . $product->pageId)->setDefaultValue(1)->addRule(function ($control) {
             return ctype_digit($control->value);
         }, 'The amount must be a number!');
     }
     $form->onSuccess[] = callback($this, $name . 'Submitted');
     $form->onError[] = callback($this, $name . 'Error');
     $form->addProtection();
     $form->addSubmit('s', 'Přidat do košíku');
     return $form;
 }
示例#14
0
文件: Gridder.php 项目: bazo/Tatami
 protected function createComponentForm($name)
 {
     $form = new Form($this, $name);
     $form->getElementPrototype()->class = 'ajax';
     $form->setTranslator($this->translator);
     if ($this->hasOperations) {
         $operations = array();
         foreach ($this->operations as $name => $operation) {
             $operations[$name] = $operation->getAlias();
         }
         $form->addSelect('operation', 'Operation', $operations);
         $form->addSubmit('btnExecuteOperation', 'Execute')->onClick[] = callback($this, 'executeOperation');
         $records = $form->addContainer('records');
         if ($form->isSubmitted()) {
             if (isset($this->persister->recordCheckboxes)) {
                 $checkboxes = $this->persister->recordCheckboxes;
                 foreach ($checkboxes as $id) {
                     $records->addCheckbox($id);
                 }
             }
         }
     }
     if ($this->hasFilters) {
         $filters = $form->addContainer('filters');
         foreach ($this->getComponents(false, 'Gridder\\Columns\\IColumn') as $column) {
             if ($column->hasFilter()) {
                 $filters->addComponent($column->getFilter(), $column->name);
                 if ($form->isSubmitted()) {
                     $httpData = $form->getHttpData();
                     if (isset($httpData['btnCancelFilters'])) {
                         unset($this->persister->filters);
                         $filters[$column->name]->setValue(null);
                     }
                 } elseif (isset($this->persister->filters[$column->name])) {
                     $filters[$column->name]->setDefaultValue($this->persister->filters[$column->name]->getValue());
                 }
             }
         }
         $form->addSubmit('btnApplyFilters', 'Apply filters')->onClick[] = callback($this, 'saveFilters');
         $form['btnApplyFilters']->getControlPrototype()->class = 'button apply';
         $form->addSubmit('btnCancelFilters', 'Cancel filters')->onClick[] = callback($this, 'cancelFilters');
         $form['btnCancelFilters']->getControlPrototype()->class = 'button cancel';
     }
 }