public function enable() { $this->validateScripts = array(); $this->toggleScript = ''; $this->central = TRUE; foreach ($this->form->getControls() as $control) { $script = $this->getValidateScript($control->getRules()); if ($script) { $this->validateScripts[$control->getHtmlName()] = $script; } $this->toggleScript .= $this->getToggleScript($control->getRules()); if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) { $this->central = FALSE; } } if ($this->validateScripts || $this->toggleScript) { if ($this->central) { $this->form->getElementPrototype()->onsubmit("return nette.validateForm(this)", TRUE); } else { foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) { if ($control->getValidationScope()) { $control->getControlPrototype()->onclick("return nette.validateForm(this)", TRUE); } } } } }
/** * Renders form end. * * @return string */ public static function renderFormEnd(Form $form) { $s = ''; if (strcasecmp($form->getMethod(), 'get') === 0) { $url = explode('?', $form->getElementPrototype()->action, 2); if (isset($url[1])) { foreach (preg_split('#[;&]#', $url[1]) as $param) { $parts = explode('=', $param, 2); $name = urldecode($parts[0]); if (!isset($form[$name])) { $s .= Nette\Utils\Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1]))); } } } } foreach ($form->getComponents(true, 'Nette\\Forms\\Controls\\HiddenField') as $control) { if (!$control->getOption('rendered')) { $s .= $control->getControl(); } } if (iterator_count($form->getComponents(true, 'Nette\\Forms\\Controls\\TextInput')) < 2) { $s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->'; } echo ($s ? "<div>{$s}</div>\n" : '') . $form->getElementPrototype()->endTag() . "\n"; }
/** * Renders form end. * @return string */ public static function renderFormEnd(Form $form, $withTags = TRUE) { $s = ''; if (strcasecmp($form->getMethod(), 'get') === 0) { foreach (preg_split('#[;&]#', parse_url($form->getElementPrototype()->action, PHP_URL_QUERY), NULL, PREG_SPLIT_NO_EMPTY) as $param) { $parts = explode('=', $param, 2); $name = urldecode($parts[0]); if (!isset($form[$name])) { $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]); } } } foreach ($form->getComponents(TRUE, Nette\Forms\Controls\HiddenField::class) as $control) { if (!$control->getOption('rendered')) { $s .= $control->getControl(); } } if (iterator_count($form->getComponents(TRUE, Nette\Forms\Controls\TextInput::class)) < 2) { $s .= "<!--[if IE]><input type=IEbug disabled style=\"display:none\"><![endif]-->\n"; } return $s . ($withTags ? $form->getElementPrototype()->endTag() . "\n" : ''); }
/** * Renders form end. * @return string */ public function renderEnd() { $s = ''; foreach ($this->form->getControls() as $control) { if ($control instanceof Nette\Forms\Controls\HiddenField && !$control->getOption('rendered')) { $s .= (string) $control->getControl(); } } if (iterator_count($this->form->getComponents(TRUE, 'Nette\\Forms\\Controls\\TextInput')) < 2) { $s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->'; } if ($s) { $s = $this->getWrapper('hidden container')->setHtml($s) . "\n"; } return $s . $this->form->getElementPrototype()->endTag() . "\n"; }
/** * @param Form */ public function save(Form $form) { $this->form = $form; $this->entities = []; $this->execute(function () { $this->entityManager->persist($this->entity); }); $this->saveValues($this->applyOffset($form->getComponents(), $this->offset), $this->entity); if (!$form->isValid()) { return; } $this->getExecutionStrategy()->confirm(); $valid = TRUE; foreach ($this->entities as $entity) { try { $this->runValidation(function (ValidatorInterface $validator) use($entity) { return $validator->validate($entity); }, $form); } catch (ValidationException $e) { $valid = FALSE; } } if ($valid && $this->getAutoFlush()) { $this->flush(); } }
/** * @param Forms\Form $form */ private function applyCallbacksToButtons(Forms\Form $form) { /** @var SubmitButton $control */ foreach ($form->getComponents(FALSE, 'Nette\\Forms\\Controls\\SubmitButton') as $control) { if (!in_array($control->getName(), array(self::FINISH_SUBMIT_NAME, self::NEXT_SUBMIT_NAME, self::PREV_SUBMIT_NAME))) { continue; } $control->onClick[] = array($this, 'submitStep'); $control->onInvalidClick[] = array($this, 'submitStep'); if ($control->getName() === self::PREV_SUBMIT_NAME) { $control->setValidationScope(FALSE); } } }