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.
This commit is contained in:
sam marshall
2013-03-28 10:46:33 +00:00
parent b2ec866fc7
commit d953b18495
+16
View File
@@ -921,6 +921,22 @@ abstract class moodleform {
$this->_form->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!
*/