PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Nette/Forms/Controls/HiddenField.php

https://github.com/DocX/nette
PHP | 85 lines | 26 code | 21 blank | 38 comment | 0 complexity | f1e052e023a68e5924954415530869ff MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt.
  9. *
  10. * For more information please see http://nettephp.com
  11. *
  12. * @copyright Copyright (c) 2004, 2009 David Grudl
  13. * @license http://nettephp.com/license Nette license
  14. * @link http://nettephp.com
  15. * @category Nette
  16. * @package Nette\Forms
  17. */
  18. /*namespace Nette\Forms;*/
  19. require_once dirname(__FILE__) . '/../../Forms/Controls/FormControl.php';
  20. /**
  21. * Hidden form control used to store a non-displayed value.
  22. *
  23. * @author David Grudl
  24. * @copyright Copyright (c) 2004, 2009 David Grudl
  25. * @package Nette\Forms
  26. */
  27. class HiddenField extends FormControl
  28. {
  29. /** @var string */
  30. private $forcedValue;
  31. public function __construct($forcedValue = NULL)
  32. {
  33. parent::__construct();
  34. $this->control->type = 'hidden';
  35. $this->value = (string) $forcedValue;
  36. $this->forcedValue = $forcedValue;
  37. }
  38. /**
  39. * Bypasses label generation.
  40. * @return void
  41. */
  42. public function getLabel($caption = NULL)
  43. {
  44. return NULL;
  45. }
  46. /**
  47. * Sets control's value.
  48. * @param string
  49. * @return HiddenField provides a fluent interface
  50. */
  51. public function setValue($value)
  52. {
  53. $this->value = is_scalar($value) ? (string) $value : '';
  54. return $this;
  55. }
  56. /**
  57. * Generates control's HTML element.
  58. * @return Nette\Web\Html
  59. */
  60. public function getControl()
  61. {
  62. return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue);
  63. }
  64. }