Add a method to HTML for getting just the HTML (As opposed to passing it right to...
authorJohn Du Hart <johnduhart@users.mediawiki.org>
Sat, 8 Oct 2011 19:13:35 +0000 (19:13 +0000)
committerJohn Du Hart <johnduhart@users.mediawiki.org>
Sat, 8 Oct 2011 19:13:35 +0000 (19:13 +0000)
Also, if a field is marked as required, it should still be checked to see if it's empty before going to the callback. Don't like that behavior? Don't mark it as required.

includes/HTMLForm.php

index 78a59f4..63a5d59 100644 (file)
@@ -374,6 +374,15 @@ class HTMLForm {
         * @param $submitResult Mixed output from HTMLForm::trySubmit()
         */
        function displayForm( $submitResult ) {
+               $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
+       }
+
+       /**
+        * Returns the raw HTML generated by the form
+        * @param $submitResult Mixed output from HTMLForm::trySubmit()
+        * @return string
+        */
+       function getHTML( $submitResult ) {
                # For good measure (it is the default)
                $this->getOutput()->preventClickjacking();
                $this->getOutput()->addModules( 'mediawiki.htmlform' );
@@ -389,11 +398,7 @@ class HTMLForm {
 
                $html = $this->wrapForm( $html );
 
-               $this->getOutput()->addHTML( ''
-                       . $this->mPre
-                       . $html
-                       . $this->mPost
-               );
+               return '' . $this->mPre . $html . $this->mPost;
        }
 
        /**
@@ -832,14 +837,14 @@ abstract class HTMLFormField {
         * @return Mixed Bool true on success, or String error to display.
         */
        function validate( $value, $alldata ) {
-               if ( isset( $this->mValidationCallback ) ) {
-                       return call_user_func( $this->mValidationCallback, $value, $alldata );
-               }
-
                if ( isset( $this->mParams['required'] ) && $value === '' ) {
                        return wfMsgExt( 'htmlform-required', 'parseinline' );
                }
 
+               if ( isset( $this->mValidationCallback ) ) {
+                       return call_user_func( $this->mValidationCallback, $value, $alldata );
+               }
+
                return true;
        }