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