Source for file HiddenField.php

Documentation is available at HiddenField.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Forms
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../../Forms/Controls/FormControl.php';
  24. 24:  
  25. 25:  
  26. 26:  
  27. 27: /**
  28. 28:  * Hidden form control used to store a non-displayed value.
  29. 29:  *
  30. 30:  * @author     David Grudl
  31. 31:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  32. 32:  * @package    Nette\Forms
  33. 33:  */
  34. 34: class HiddenField extends FormControl
  35. 35: {
  36. 36:     /** @var string */
  37. 37:     private $forcedValue;
  38. 38:  
  39. 39:  
  40. 40:  
  41. 41:     public function __construct($forcedValue NULL)
  42. 42:     {
  43. 43:         parent::__construct(NULL);
  44. 44:         $this->control->type 'hidden';
  45. 45:         $this->value = (string) $forcedValue;
  46. 46:         $this->forcedValue $forcedValue;
  47. 47:     }
  48. 48:  
  49. 49:  
  50. 50:  
  51. 51:     /**
  52. 52:      * Bypasses label generation.
  53. 53:      * @return void 
  54. 54:      */
  55. 55:     public function getLabel()
  56. 56:     {
  57. 57:         return NULL;
  58. 58:     }
  59. 59:  
  60. 60:  
  61. 61:  
  62. 62:     /**
  63. 63:      * Sets control's value.
  64. 64:      * @param  string 
  65. 65:      * @return void 
  66. 66:      */
  67. 67:     public function setValue($value)
  68. 68:     {
  69. 69:         $this->value = is_scalar($value? (string) $value '';
  70. 70:     }
  71. 71:  
  72. 72:  
  73. 73:  
  74. 74:     /**
  75. 75:      * Generates control's HTML element.
  76. 76:      * @return Html 
  77. 77:      */
  78. 78:     public function getControl()
  79. 79:     {
  80. 80:         return parent::getControl()->value($this->forcedValue === NULL $this->value : $this->forcedValue);
  81. 81:     }
  82. 82:  
  83. 83: }