aboutsummaryrefslogtreecommitdiff
path: root/templates/forms/form.php
blob: 4745225414db9e1858bb65d4cdb8a543d2b4543d (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?
$inputs = [];
$allinputs = $form->getAllInputs();
$required_inputs = [];
$server_validation = false;
foreach ($allinputs as $input) {
    foreach ($input->getAllInputNames() as $name) {
        $inputs[$name] = $input->getValue();
    }
    if ($input->required) {
        $required_inputs[] = $input->getName();
    }
    if ($input->hasValidation()) {
        $server_validation = true;
    }
}
$form_id = md5(uniqid());
?><form v-cloak
      method="post"
      <? if (!$form->isAutoStoring()) : ?>
          action="<?= htmlReady($form->getURL()) ?>"
      <? else : ?>
          data-autosave="<?= htmlReady($_SERVER['REQUEST_URI']) ?>"
          data-url="<?= htmlReady($form->getURL()) ?>"
      <? endif ?>
      @submit="submit"
      @cancel=""
      novalidate
      <?= $form->getDataSecure() ? 'data-secure' : '' ?>
      id="<?= htmlReady($form_id) ?>"
      data-inputs="<?= htmlReady(json_encode($inputs)) ?>"
      data-debugmode="<?= htmlReady(json_encode($form->getDebugMode())) ?>"
      data-required="<?= htmlReady(json_encode($required_inputs)) ?>"
      data-server_validation="<?= $server_validation ? 1 : 0?>"
      data-validation_url="<?= htmlReady($_SERVER['REQUEST_URI']) ?>"
      class="default studipform<?= $form->isCollapsable() ? ' collapsable' : '' ?>">

    <?= CSRFProtection::tokenTag(['ref' => 'securityToken']) ?>

    <article aria-live="assertive"
             class="validation_notes studip"
             v-if="STUDIPFORM_REQUIRED.length > 0 || STUDIPFORM_VALIDATIONNOTES.length > 0">
        <header>
            <h1>
                <?= Icon::create('info-circle', Icon::ROLE_INFO)->asImg(17, ['class' => "text-bottom validation_notes_icon"]) ?>
                <?= _('Hinweise zum Ausfüllen des Formulars') ?>
            </h1>
        </header>
        <div class="required_note" v-if="STUDIPFORM_REQUIRED.length > 0">
            <div aria-hidden="true">
                <?= _('Pflichtfelder sind mit Sternchen gekennzeichnet.') ?>
            </div>
            <div class="sr-only">
                <?= _('Dieses Formular enthält Pflichtfelder.') ?>
            </div>

        </div>
        <div v-if="STUDIPFORM_DISPLAYVALIDATION && (STUDIPFORM_VALIDATIONNOTES.length > 0)">
            <?= _('Folgende Angaben müssen korrigiert werden, um das Formular abschicken zu können:') ?>
            <ul>
                <li v-for="note in ordererValidationNotes" :aria-describedby="note.describedby">{{ note.label.trim() + ": " + note.description }}</li>
            </ul>
        </div>
    </article>

    <div aria-live="polite">
    <? foreach ($form->getParts() as $part) : ?>
        <?= $part->renderWithCondition() ?>
    <? endforeach ?>
    </div>
    <? if (!Request::isDialog()) : ?>
        <footer>
            <?= \Studip\Button::createAccept($form->getSaveButtonText(), $form->getSaveButtonName(), ['form' => $form_id]) ?>
            <?= \Studip\LinkButton::createCancel($form->getCancelButtonText(), $form->getCancelButtonName()) ?>
        </footer>
    <? endif ?>
</form>
<? if (Request::isDialog()) : ?>
    <footer data-dialog-button>
        <?= \Studip\Button::create($form->getSaveButtonText(), $form->getSaveButtonName(), ['form' => $form_id]) ?>
        <? foreach ($form->getButtons() as $button) : ?>
            <?
            $button->attributes['form'] = $form_id;
            echo $button;
            ?>
        <? endforeach ?>
    </footer>
<? endif ?>