Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit d953b18495c82e7ac48b7d4b75fc4972df0f7ed6 1 parent b2ec866
sam marshall sammarshallou authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/formslib.php
16 lib/formslib.php
View
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.