HTMLHiddenField.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. class HTMLHiddenField extends HTMLFormField {
  3. protected $outputAsDefault = true;
  4. public function __construct( $params ) {
  5. parent::__construct( $params );
  6. if ( isset( $this->mParams['output-as-default'] ) ) {
  7. $this->outputAsDefault = (bool)$this->mParams['output-as-default'];
  8. }
  9. # Per HTML5 spec, hidden fields cannot be 'required'
  10. # https://www.w3.org/TR/html5/forms.html#hidden-state-%28type=hidden%29
  11. unset( $this->mParams['required'] );
  12. }
  13. public function getHiddenFieldData( $value ) {
  14. $params = [];
  15. if ( $this->mID ) {
  16. $params['id'] = $this->mID;
  17. }
  18. if ( $this->outputAsDefault ) {
  19. $value = $this->mDefault;
  20. }
  21. return [ $this->mName, $value, $params ];
  22. }
  23. public function getTableRow( $value ) {
  24. list( $name, $value, $params ) = $this->getHiddenFieldData( $value );
  25. $this->mParent->addHiddenField( $name, $value, $params );
  26. return '';
  27. }
  28. /**
  29. * @param string $value
  30. * @return string
  31. * @since 1.20
  32. */
  33. public function getDiv( $value ) {
  34. return $this->getTableRow( $value );
  35. }
  36. /**
  37. * @param string $value
  38. * @return string
  39. * @since 1.20
  40. */
  41. public function getRaw( $value ) {
  42. return $this->getTableRow( $value );
  43. }
  44. public function getInputHTML( $value ) {
  45. return '';
  46. }
  47. public function canDisplayErrors() {
  48. return false;
  49. }
  50. public function hasVisibleOutput() {
  51. return false;
  52. }
  53. }