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