Improve HTMLSubmitField return value
[lhc/web/wiklou.git] / includes / htmlform / HTMLForm.php
index bf46e55..6878399 100644 (file)
  *                             Some field types support multi-level arrays.
  *    'options-messages'    -- associative array mapping message keys to values.
  *                             Some field types support multi-level arrays.
- *    'options-message'     -- message key to be parsed to extract the list of
+ *    'options-message'     -- message key or object to be parsed to extract the list of
  *                             options (like 'ipbreason-dropdown').
- *    'label-message'       -- message key for a message to use as the label.
+ *    'label-message'       -- message key or object for a message to use as the label.
  *                             can be an array of msg key and then parameters to
  *                             the message.
  *    'label'               -- alternatively, a raw text message. Overridden by
  *                             label-message
  *    'help'                -- message text for a message to use as a help text.
- *    'help-message'        -- message key for a message to use as a help text.
+ *    'help-message'        -- message key or object for a message to use as a help text.
  *                             can be an array of msg key and then parameters to
  *                             the message.
  *                             Overwrites 'help-messages' and 'help'.
- *    'help-messages'       -- array of message key. As above, each item can
+ *    'help-messages'       -- array of message keys/objects. As above, each item can
  *                             be an array of msg key and then parameters.
  *                             Overwrites 'help'.
  *    'required'            -- passed through to the object, indicating that it
@@ -180,6 +180,7 @@ class HTMLForm extends ContextSource {
        protected $mSectionFooters = [];
        protected $mPost = '';
        protected $mId;
+       protected $mName;
        protected $mTableId = '';
 
        protected $mSubmitID;
@@ -1006,6 +1007,9 @@ class HTMLForm extends ContextSource {
                if ( !empty( $this->mAutocomplete ) ) {
                        $attribs['autocomplete'] = $this->mAutocomplete;
                }
+               if ( !empty ( $this->mName ) ) {
+                       $attribs['name'] = $this->mName;
+               }
                return $attribs;
        }
 
@@ -1347,6 +1351,16 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * @param string $name 'name' attribute for the form
+        * @return HTMLForm $this for chaining calls
+        */
+       public function setName( $name ) {
+               $this->mName = $name;
+
+               return $this;
+       }
+
        /**
         * Prompt the whole form to be wrapped in a "<fieldset>", with
         * this text as its "<legend>" element.
@@ -1481,7 +1495,7 @@ class HTMLForm extends ContextSource {
 
                foreach ( $fields as $key => $value ) {
                        if ( $value instanceof HTMLFormField ) {
-                               $v = empty( $value->mParams['nodata'] )
+                               $v = isset( $this->mFieldData[$key] )
                                        ? $this->mFieldData[$key]
                                        : $value->getDefault();
 
@@ -1590,12 +1604,13 @@ class HTMLForm extends ContextSource {
                $fieldData = [];
 
                foreach ( $this->mFlatFields as $fieldname => $field ) {
-                       if ( !empty( $field->mParams['nodata'] ) ) {
+                       $request = $this->getRequest();
+                       if ( $field->skipLoadData( $request ) ) {
                                continue;
                        } elseif ( !empty( $field->mParams['disabled'] ) ) {
                                $fieldData[$fieldname] = $field->getDefault();
                        } else {
-                               $fieldData[$fieldname] = $field->loadDataFromRequest( $this->getRequest() );
+                               $fieldData[$fieldname] = $field->loadDataFromRequest( $request );
                        }
                }