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:
@@ -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!
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user