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
34
35
| <?php
|
| use JVBase\meta\Form;
|
| if (!defined('ABSPATH')) {
| exit;
| }
|
| function jvbRenderForm(string $endpoint, array $fields, 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) {
| echo Form::render($field, null, $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;
| }
|
|