Elgg\FormsService::render PHP Method

render() public method

This function assumes that the body of the form is located at "forms/$action" and sets the action by default to "action/$action". Automatically wraps the forms/$action view with a
tag and inserts the anti-csrf security tokens.
public render ( string $action, array $form_vars = [], array $body_vars = [] ) : string
$action string The name of the action. An action name does not include the leading "action/". For example, "login" is an action name.
$form_vars array $vars passed to the "input/form" view
$body_vars array $vars passed to the "forms/" view
return string The complete form
    public function render($action, $form_vars = array(), $body_vars = array())
    {
        $defaults = array('action' => elgg_normalize_url("action/{$action}"));
        // append elgg-form class to any class options set
        $form_vars['class'] = (array) elgg_extract('class', $form_vars, []);
        $form_vars['class'][] = 'elgg-form-' . preg_replace('/[^a-z0-9]/i', '-', $action);
        $form_vars = array_merge($defaults, $form_vars);
        $form_vars['action_name'] = $action;
        if (!isset($form_vars['body'])) {
            $this->rendering = true;
            $this->footer = '';
            // Render form body
            $body = $this->views->renderView("forms/{$action}", $body_vars);
            if (!empty($body)) {
                // Grab the footer if one was set during form rendering
                $body .= $this->views->renderView('elements/forms/footer', ['footer' => $this->getFooter(), 'action_name' => $action]);
            }
            $this->rendering = false;
            $form_vars['body'] = $body;
        }
        return elgg_view('input/form', $form_vars);
    }