form/daterange
< >

return function () {
    $assets = _class('assets');
    $versions = array_keys((array) ($assets->get_asset_details('bootstrap-daterangepicker')['versions'] ?? []));
    // the descriptor lists the newer builds first and the default last
    $newer = count($versions) > 1 && ($_GET['drp'] ?? '') === 'newer';
    $newer && $assets->VERSION_PINS['bootstrap-daterangepicker'] = (string) reset($versions);
    $lang = in_array($_GET['lang'] ?? '', ['ru', 'uk', 'de'], true) ? $_GET['lang'] : '';
    $lang !== '' && conf('language', $lang);
    $query = '?drp=' . ($newer ? 'newer' : 'default') . ($lang !== '' ? '&lang=' . $lang : '');
    $self = url('/@object/@action/' . urlencode('form/daterange'));
    $links = [];
    foreach (['default' => 'the default build', 'newer' => 'the newer build (opt-in)'] as $key => $label) {
        $links[] = ($key === 'newer') === $newer ? '<b>' . $label . '</b>' : '<a href="' . $self . '?drp=' . $key . '">' . $label . '</a>';
    }
    $intro = '<p class="docs-demo-intro">The <code>daterange_select()</code> control (alias <code>daterange()</code>) with
        bootstrap-daterangepicker: ' . implode(', ', $links) . '. A site picks the newer one with
        <code>$PROJECT_CONF[\'assets\'][\'VERSION_PINS\'][\'bootstrap-daterangepicker\']</code>; its markup and stylesheet differ, the
        posted values do not. The first field has no limits, the second one allows 5..25 Nov 2026 as the payment admin filters do,
        the third one uses the d.m.Y format of the revisions filter. The field posts one value "from - to"; below, the server shows
        how the table2 filter conditions <code>daterange_dt_between</code> and <code>daterange_between</code> read it. The demo stores
        nothing. Classes: <code>yf_form2</code>, <code>yf_form2_daterange</code>.</p>';
    $form_id = 'docs_daterange';
    $fields = ['dr_plain', 'dr_minmax', 'dr_dmy'];
    $result = '';
    $form = form((array) $_POST, ['csrf' => true, '__form_id__' => $form_id, 'id' => 'dr_form', 'action' => $self . $query])
        ->validate(['__form_id__' => $form_id] + array_fill_keys($fields, 'trim'))
        ->on_validate_ok(function ($data) use (&$result, $fields) {
            $filter = _class('table2_filter', 'classes/table2/');
            $filter->_init();
            $conds = $filter->supported_conds;
            $out = [];
            foreach ($fields as $name) {
                $value = (string) ($data[$name] ?? '');
                $out[$name] = [
                    'raw' => $value,
                    'daterange_dt_between' => $conds['daterange_dt_between'](['value' => $value]),
                    'daterange_between' => $conds['daterange_between'](['value' => $value]),
                ];
            }
            $json = json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            $result = '<div class="alert alert-success" id="dr_result"><b>Received</b> (nothing stored):<pre>' . _prepare_html($json, 0) . '</pre></div>';
        })
        ->daterange_select('dr_plain', 'No limits')
        ->daterange_select('dr_minmax', 'Min / max', ['format' => 'YYYY-MM-DD', 'min_date' => '2026-11-05', 'max_date' => '2026-11-25', 'autocomplete' => 'off'])
        ->daterange_select('dr_dmy', 'd.m.Y', ['format' => 'DD.MM.YYYY', 'min_date' => '01.11.2026', 'max_date' => '30.11.2026', 'autocomplete' => 'off'])
        ->save();
    // A failed CSRF check logs into the log_csrf_errors table; the demo writes no rows
    $guard = _class('csrf_guard');
    $log_errors = $guard->LOG_ERRORS;
    $guard->LOG_ERRORS = false;
    try {
        $html = (string) $form;
    } finally {
        $guard->LOG_ERRORS = $log_errors;
    }
    return $intro . $result . $html;
};

The daterange_select() control (alias daterange()) with bootstrap-daterangepicker: the default build, the newer build (opt-in). A site picks the newer one with $PROJECT_CONF['assets']['VERSION_PINS']['bootstrap-daterangepicker']; its markup and stylesheet differ, the posted values do not. The first field has no limits, the second one allows 5..25 Nov 2026 as the payment admin filters do, the third one uses the d.m.Y format of the revisions filter. The field posts one value "from - to"; below, the server shows how the table2 filter conditions daterange_dt_between and daterange_between read it. The demo stores nothing. Classes: yf_form2, yf_form2_daterange.