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