1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://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\Controls;
13:
14: use Nette;
15:
16:
17: /**
18: * Hidden form control used to store a non-displayed value.
19: *
20: * @author David Grudl
21: */
22: class HiddenField extends BaseControl
23: {
24: /** @var string */
25: private $forcedValue;
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: * Bypasses label generation.
39: * @return void
40: */
41: public function getLabel($caption = NULL)
42: {
43: return NULL;
44: }
45:
46:
47: /**
48: * Sets control's value.
49: * @param string
50: * @return self
51: */
52: public function setValue($value)
53: {
54: $this->value = is_scalar($value) ? (string) $value : '';
55: return $this;
56: }
57:
58:
59: /**
60: * Generates control's HTML element.
61: * @return Nette\Utils\Html
62: */
63: public function getControl()
64: {
65: return parent::getControl()
66: ->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)
67: ->data('nette-rules', NULL);
68: }
69:
70: }
71: