Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

  • FormMacros
  • Runtime
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Bridges\FormsLatte;
 9: 
10: use Nette;
11: use Nette\Forms\Form;
12: use Nette\Utils\Html;
13: 
14: 
15: /**
16:  * Runtime helpers for Latte.
17:  * @internal
18:  */
19: class Runtime
20: {
21:     use Nette\StaticClass;
22: 
23:     /**
24:      * Renders form begin.
25:      * @return string
26:      */
27:     public static function renderFormBegin(Form $form, array $attrs, $withTags = true)
28:     {
29:         $form->fireRenderEvents();
30:         foreach ($form->getControls() as $control) {
31:             $control->setOption('rendered', false);
32:         }
33:         $el = $form->getElementPrototype();
34:         $el->action = (string) $el->action;
35:         $el = clone $el;
36:         if ($form->isMethod('get')) {
37:             $el->action = preg_replace('~\?[^#]*~', '', $el->action, 1);
38:         }
39:         $el->addAttributes($attrs);
40:         return $withTags ? $el->startTag() : $el->attributes();
41:     }
42: 
43: 
44:     /**
45:      * Renders form end.
46:      * @return string
47:      */
48:     public static function renderFormEnd(Form $form, $withTags = true)
49:     {
50:         $s = '';
51:         if ($form->isMethod('get')) {
52:             foreach (preg_split('#[;&]#', (string) parse_url($form->getElementPrototype()->action, PHP_URL_QUERY), -1, PREG_SPLIT_NO_EMPTY) as $param) {
53:                 $parts = explode('=', $param, 2);
54:                 $name = urldecode($parts[0]);
55:                 $prefix = explode('[', $name, 2)[0];
56:                 if (!isset($form[$prefix])) {
57:                     $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]);
58:                 }
59:             }
60:         }
61: 
62:         foreach ($form->getControls() as $control) {
63:             if ($control->getOption('type') === 'hidden' && !$control->getOption('rendered')) {
64:                 $s .= $control->getControl();
65:             }
66:         }
67: 
68:         if (iterator_count($form->getComponents(true, Nette\Forms\Controls\TextInput::class)) < 2) {
69:             $s .= "<!--[if IE]><input type=IEbug disabled style=\"display:none\"><![endif]-->\n";
70:         }
71: 
72:         return $s . ($withTags ? $form->getElementPrototype()->endTag() . "\n" : '');
73:     }
74: }
75: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0