Permalink
Browse files

MDL-26956 (2) Forms: Function to render form to string

Previously it was only possible to display the form immediately as
HTML output. You had to wrap in an output buffer in order to put
it in a renderer. This new function does the output buffer for you.
  • Loading branch information...
1 parent b2ec866 commit d953b18495c82e7ac48b7d4b75fc4972df0f7ed6 @sammarshallou sammarshallou committed Mar 27, 2013
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/formslib.php
View
16 lib/formslib.php
@@ -922,6 +922,22 @@ function display() {
}
/**
+ * Renders the html form (same as display, but returns the result).
+ *
+ * Note that you can only output this rendered result once per page, as
+ * it contains IDs which must be unique.
+ *
+ * @return string HTML code for the form
+ */
+ public function render() {
+ ob_start();
+ $this->display();
+ $out = ob_get_contents();
+ ob_end_clean();
+ return $out;
+ }
+
+ /**
* Form definition. Abstract method - always override!
*/
protected abstract function definition();

0 comments on commit d953b18

Please sign in to comment.