class HTMLForm extends ContextSource {
// A mapping of 'type' inputs onto standard HTMLFormField subclasses
- static $typeMappings = array(
+ private static $typeMappings = array(
'api' => 'HTMLApiField',
'text' => 'HTMLTextField',
'textarea' => 'HTMLTextAreaField',
protected $mFieldTree;
protected $mShowReset = false;
+ protected $mShowSubmit = true;
public $mFieldData;
protected $mSubmitCallback;
*/
public function setDisplayFormat( $format ) {
if ( !in_array( $format, $this->availableDisplayFormats ) ) {
- throw new MWException ( 'Display format must be one of ' . print_r( $this->availableDisplayFormats, true ) );
+ throw new MWException( 'Display format must be one of ' . print_r( $this->availableDisplayFormats, true ) );
}
$this->displayFormat = $format;
return $this;
}
/**
- * Validate all the fields, and call the submision callback
+ * Validate all the fields, and call the submission callback
* function if everything is kosher.
* @throws MWException
* @return Mixed Bool true == Successful submission, Bool false
*/
function getButtons() {
$html = '';
- $attribs = array();
- if ( isset( $this->mSubmitID ) ) {
- $attribs['id'] = $this->mSubmitID;
- }
+ if ( $this->mShowSubmit ) {
+ $attribs = array();
- if ( isset( $this->mSubmitName ) ) {
- $attribs['name'] = $this->mSubmitName;
- }
+ if ( isset( $this->mSubmitID ) ) {
+ $attribs['id'] = $this->mSubmitID;
+ }
- if ( isset( $this->mSubmitTooltip ) ) {
- $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
- }
+ if ( isset( $this->mSubmitName ) ) {
+ $attribs['name'] = $this->mSubmitName;
+ }
- $attribs['class'] = 'mw-htmlform-submit';
+ if ( isset( $this->mSubmitTooltip ) ) {
+ $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
+ }
+
+ $attribs['class'] = 'mw-htmlform-submit';
- $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
+ $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
+ }
if ( $this->mShowReset ) {
$html .= Html::element(
return $this;
}
+ /**
+ * Stop a default submit button being shown for this form. This implies that an
+ * alternate submit method must be provided manually.
+ *
+ * @since 1.22
+ *
+ * @param bool $suppressSubmit Set to false to re-enable the button again
+ *
+ * @return HTMLForm $this for chaining calls
+ */
+ function suppressDefaultSubmit( $suppressSubmit = true ) {
+ $this->mShowSubmit = !$suppressSubmit;
+ return $this;
+ }
+
/**
* @param string $id DOM id for the form
* @return HTMLForm $this for chaining calls (since 1.20)
/**
* Set the prefix for various default messages
* @todo currently only used for the "<fieldset>" legend on forms
- * with multiple sections; should be used elsewhre?
+ * with multiple sections; should be used elsewhere?
* @param $p String
* @return HTMLForm $this for chaining calls (since 1.20)
*/
/**
* Get a translated interface message
*
- * This is a wrapper arround $this->mParent->msg() if $this->mParent is set
+ * This is a wrapper around $this->mParent->msg() if $this->mParent is set
* and wfMessage() otherwise.
*
* Parameters are the same as wfMessage().
* Select dropdown field, with an additional "other" textbox.
*/
class HTMLSelectOrOtherField extends HTMLTextField {
- static $jsAdded = false;
function __construct( $params ) {
if ( !in_array( 'other', $params['options'], true ) ) {
}
public function getInputHTML( $value ) {
- return Xml::submitButton(
- $value,
- array(
- 'class' => 'mw-htmlform-submit ' . $this->mClass,
- 'name' => $this->mName,
- 'id' => $this->mID,
- )
+ $attr = array(
+ 'class' => 'mw-htmlform-submit ' . $this->mClass,
+ 'name' => $this->mName,
+ 'id' => $this->mID,
);
+
+ if ( !empty( $this->mParams['disabled'] ) ) {
+ $attr['disabled'] = 'disabled';
+ }
+
+ return Xml::submitButton( $value, $attr );
}
protected function needsLabel() {