Jake Vanderwerf
2026-01-02 b5abd615697146beeca6dba4acd057d049554a30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
 
if (!defined('ABSPATH')) {
    exit;
}
 
function jvbRenderForm(string $endpoint, array $fields, JVBase\meta\MetaManager $meta, array $options = [], bool $return = false):mixed
{
    ob_start();
    ?>
    <form id="<?= $endpoint ?>" data-save="<?=$endpoint?>">
        <?= (array_key_exists('heading', $options)) ? '<h2>'.$options['heading'].'</h2>' : '' ?>
        <?php
        if (array_key_exists('description', $options)) {
            foreach ($options['description'] as $d) {
                echo '<p>'.$d.'</p>';
            }
        }
 
        foreach ($fields as $field => $config) {
            $meta->render('form', $field, $config);
        }
        ?>
        <?= (jvbCheck('submit', $options)) ? '<button type="submit">'.jvbIcon('floppy-disk').'Save</button>' : '' ?>
    </form>
    <?php
    $out = ob_get_clean();
    if ($return) {
        return $out;
    }
    echo $out;
    return true;
}