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

  • BaseControl
  • Button
  • Checkbox
  • CheckboxList
  • ChoiceControl
  • CsrfProtection
  • HiddenField
  • ImageButton
  • MultiChoiceControl
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • 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\Forms\Controls;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Hidden form control used to store a non-displayed value.
15:  */
16: class HiddenField extends BaseControl
17: {
18:     /** @var bool */
19:     private $persistValue;
20: 
21: 
22:     public function __construct($persistentValue = null)
23:     {
24:         parent::__construct();
25:         $this->control->type = 'hidden';
26:         $this->setOption('type', 'hidden');
27:         if ($persistentValue !== null) {
28:             $this->unmonitor(Nette\Forms\Form::class);
29:             $this->persistValue = true;
30:             $this->value = (string) $persistentValue;
31:         }
32:     }
33: 
34: 
35:     /**
36:      * Sets control's value.
37:      * @param  string
38:      * @return static
39:      * @internal
40:      */
41:     public function setValue($value)
42:     {
43:         if (!is_scalar($value) && $value !== null && !method_exists($value, '__toString')) {
44:             throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", gettype($value), $this->name));
45:         }
46:         if (!$this->persistValue) {
47:             $this->value = (string) $value;
48:         }
49:         return $this;
50:     }
51: 
52: 
53:     /**
54:      * Generates control's HTML element.
55:      * @return Nette\Utils\Html
56:      */
57:     public function getControl()
58:     {
59:         $this->setOption('rendered', true);
60:         $el = clone $this->control;
61:         return $el->addAttributes([
62:             'name' => $this->getHtmlName(),
63:             'disabled' => $this->isDisabled(),
64:             'value' => $this->value,
65:         ]);
66:     }
67: 
68: 
69:     /**
70:      * Bypasses label generation.
71:      * @param  string|object
72:      * @return void
73:      */
74:     public function getLabel($caption = null)
75:     {
76:     }
77: 
78: 
79:     /**
80:      * Adds error message to the list.
81:      * @param  string|object
82:      * @return void
83:      */
84:     public function addError($message, $translate = true)
85:     {
86:         $this->getForm()->addError($message, $translate);
87:     }
88: }
89: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0