1: <?php
2:
3: /**
4: * This file is part of the Nette Framework.
5: *
6: * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
7: *
8: * This source file is subject to the "Nette license", and/or
9: * GPL license. For more information please see http://nette.org
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: */
20: class HiddenField extends FormControl
21: {
22: /** @var string */
23: private $forcedValue;
24:
25:
26:
27: public function __construct($forcedValue = NULL)
28: {
29: parent::__construct();
30: $this->control->type = 'hidden';
31: $this->value = (string) $forcedValue;
32: $this->forcedValue = $forcedValue;
33: }
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: /**
49: * Sets control's value.
50: * @param string
51: * @return HiddenField provides a fluent interface
52: */
53: public function setValue($value)
54: {
55: $this->value = is_scalar($value) ? (string) $value : '';
56: return $this;
57: }
58:
59:
60:
61: /**
62: * Generates control's HTML element.
63: * @return Html
64: */
65: public function getControl()
66: {
67: return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)->data('nette-rules', NULL);
68: }
69:
70: }
71: