1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: * @package Nette\Forms\Controls
7: */
8:
9:
10:
11: /**
12: * Hidden form control used to store a non-displayed value.
13: *
14: * @author David Grudl
15: * @package Nette\Forms\Controls
16: */
17: class NHiddenField extends NFormControl
18: {
19: /** @var string */
20: private $forcedValue;
21:
22:
23: public function __construct($forcedValue = NULL)
24: {
25: parent::__construct();
26: $this->control->type = 'hidden';
27: $this->value = (string) $forcedValue;
28: $this->forcedValue = $forcedValue;
29: }
30:
31:
32: /**
33: * Sets control's value.
34: * @param string
35: * @return self
36: */
37: public function setValue($value)
38: {
39: $this->value = is_scalar($value) ? (string) $value : '';
40: return $this;
41: }
42:
43:
44: /**
45: * Generates control's HTML element.
46: * @return NHtml
47: */
48: public function getControl()
49: {
50: return parent::getControl()
51: ->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)
52: ->data('nette-rules', NULL);
53: }
54:
55:
56: /**
57: * Bypasses label generation.
58: * @return void
59: */
60: public function getLabel($caption = NULL)
61: {
62: return NULL;
63: }
64:
65: }
66: