HTMLFormField subclasses are supposed to handle error display but some (like hidden fields) have no means of doing this. Add a HTMLFormField::canDisplayErrors() method which can be overridden to return false, in which case HTMLForm will take care of the error display. Also adds a 'rawmessage' message which can be used to wrap arbitrary text. This can be passed to methods which expect a message specifier array but do not allow a message object (so the RawMessage class cannot be used), such as HTMLFormField::trySubmit(). Bug: T112635 Change-Id: I5d73536805774ff2ee0ec64b5442650c4888dc84
62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
class HTMLHiddenField extends HTMLFormField {
|
|
protected $outputAsDefault = true;
|
|
|
|
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'
|
|
# http://www.w3.org/TR/html5/forms.html#hidden-state-%28type=hidden%29
|
|
unset( $this->mParams['required'] );
|
|
}
|
|
|
|
public function getHiddenFieldData( $value ) {
|
|
$params = array();
|
|
if ( $this->mID ) {
|
|
$params['id'] = $this->mID;
|
|
}
|
|
|
|
if ( $this->outputAsDefault ) {
|
|
$value = $this->mDefault;
|
|
}
|
|
|
|
return array( $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;
|
|
}
|
|
}
|