form/top_save
< >

return function () {
    $intro = '<p class="docs-demo-intro">' . t('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">' . t('Received: <b>%buttons</b>, field f1 = %f1 (nothing stored)', [
            '%buttons' => _prepare_html(implode(', ', $got) ?: t('no button')),
            '%f1' => _prepare_html(is_string($_POST['f1'] ?? null) ? $_POST['f1'] : ''),
        ]) . '</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, t('Field %n', ['%n' => $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>' . t('Long form') . '</h4>' . $long . '<h4>' . t('Short form') . '</h4>' . $short;
};

Форма, вища за екран, отримує компактну копію кнопки збереження зверху, вирівняну праворуч (TOP_SAVE: увімкнено в адмінці, вимкнено в користувацькій частині; ця сторінка його вмикає). Копія — це кнопка надсилання тієї самої форми з тими самими іменем і значенням, що й нижня, тож сервер не може їх розрізнити. Сервер додає її, коли рядки перед кнопкою збереження важать TOP_SAVE_MIN_ROWS (12) або більше (textarea рахується як 3, візуальний редактор — 8, вкладки — за найдовшою вкладкою); ресурс yf_form_top_save потім ховає її, поки форма вміщується у вікні. Коротка форма нижче її не отримує. Демо нічого не зберігає. Класи: yf_form2, yf_admin_ui.

Довга форма

Коротка форма