form/top_save
< >

return function () {
    $intro = '<p class="docs-demo-intro">A form taller than a screen gets a compact copy of its save button at the top, right-aligned
        (<code>TOP_SAVE</code>: on in the admin, off on the user side; this page turns it on). The copy is a submit button of the same form
        with the same name and value as the bottom one, so the server cannot tell them apart. The server adds it when the rows before the
        save button weigh <code>TOP_SAVE_MIN_ROWS</code> (12) or more (a textarea counts 3, a rich editor 8, tabs their longest tab); the
        asset <code>yf_form_top_save</code> then hides it while the form fits in the window. The short form below gets none. The demo
        stores nothing. Classes: <code>yf_form2</code>, <code>yf_admin_ui</code>.</p>';
    $result = '';
    if (is_post()) {
        $got = [];
        foreach (['top_save_go', 'save'] as $name) {
            isset($_POST[$name]) && is_string($_POST[$name]) && $got[] = $name . '=' . $_POST[$name];
        }
        $result = '<div class="alert alert-success" id="top_save_result">Received: <b>' . _prepare_html(implode(', ', $got) ?: 'no button') . '</b>, field f1 = '
            . _prepare_html(is_string($_POST['f1'] ?? null) ? $_POST['f1'] : '') . ' (nothing stored)</div>';
    }
    $f2 = _class('form2');
    $saved = $f2->TOP_SAVE;
    $f2->TOP_SAVE = true;
    try {
        $long = form((array) $_POST, ['id' => 'top_save_long', '__form_id__' => 'docs_top_save_long']);
        for ($i = 1; $i <= 24; $i++) {
            $long->text('f' . $i, 'Field ' . $i);
        }
        $long = (string) $long->textarea('notes', 'Notes')->save('top_save_go', 'Save');
        $short = (string) form([], ['id' => 'top_save_short', '__form_id__' => 'docs_top_save_short'])->text('title')->save();
    } finally {
        $f2->TOP_SAVE = $saved;
    }
    return $intro . $result . '<h4>Long form</h4>' . $long . '<h4>Short form</h4>' . $short;
};

A form taller than a screen gets a compact copy of its save button at the top, right-aligned (TOP_SAVE: on in the admin, off on the user side; this page turns it on). The copy is a submit button of the same form with the same name and value as the bottom one, so the server cannot tell them apart. The server adds it when the rows before the save button weigh TOP_SAVE_MIN_ROWS (12) or more (a textarea counts 3, a rich editor 8, tabs their longest tab); the asset yf_form_top_save then hides it while the form fits in the window. The short form below gets none. The demo stores nothing. Classes: yf_form2, yf_admin_ui.

Long form

Short form