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: */
11:
12: namespace Nette\Forms;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Hidden form control used to store a non-displayed value.
20: *
21: * @author David Grudl
22: */
23: class HiddenField extends FormControl
24: {
25: /** @var string */
26: private $forcedValue;
27:
28:
29:
30: public function __construct($forcedValue = NULL)
31: {
32: parent::__construct();
33: $this->control->type = 'hidden';
34: $this->value = (string) $forcedValue;
35: $this->forcedValue = $forcedValue;
36: }
37:
38:
39:
40: /**
41: * Bypasses label generation.
42: * @return void
43: */
44: public function getLabel($caption = NULL)
45: {
46: return NULL;
47: }
48:
49:
50:
51: /**
52: * Sets control's value.
53: * @param string
54: * @return HiddenField provides a fluent interface
55: */
56: public function setValue($value)
57: {
58: $this->value = is_scalar($value) ? (string) $value : '';
59: return $this;
60: }
61:
62:
63:
64: /**
65: * Generates control's HTML element.
66: * @return Nette\Web\Html
67: */
68: public function getControl()
69: {
70: return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue);
71: }
72:
73: }
74: