Forenindex » Programmierung/Entwicklung » PHP und MySQL » Formular / leere Options ausblenden

Formular / leere Options ausblenden

Berni
Beiträge gesamt: 66

14. Apr 2020, 18:31
Bewertung:

gelesen: 26802

Beitrag als Lesezeichen
Hallo, ich benutze ein Template innerhalb Contao, um ein Formular anzuzeigen. Durch Kundenwunsch bin ich gezwungen, mit Konstanten zu arbeiten, die an einer Stelle ins System eingetragen werden und dann im Formular (Radiofelder) ausgegeben werden. Ich muss 5 Felder vorgeben und im CMS-Backend auch 5 Options anlegen. Ist jedoch eine Option ohne Wert, wird trotzdem der Auswahlpunkt angezeigt.

Kann eine Prüfung stattfinden, ob die Options auch einen Wert haben... wenn Nein, dann ausblenden?

Code
<?php foreach ($this->getOptions() as $option): ?> 
<?php if ($option['type'] == 'group_start'): ?>
<fieldset>
<legend><?= $option['label'] ?></legend>
<?php endif; ?>

<?php if ($option['type'] == 'option'): ?>
<span><input type="radio" name="<?= $option['name'] ?>" id="opt_<?= $option['id'] ?>" class="radio" value="<?= $option['value'] ?>"<?= $option['checked'] ?><?= $option['attributes'] ?>> <label id="lbl_<?= $option['id'] ?>" for="opt_<?= $option['id'] ?>"><?= $option['label'] ?></label></span>
<?php endif; ?>

<?php if ($option['type'] == 'group_end'): ?>
</fieldset>
<?php endif; ?>
<?php endforeach; ?>

Formular / leere Options ausblenden

Heini5000
Beiträge gesamt: 9

31. Okt 2020, 06:44
Bewertung:

gelesen: 19176

Beitrag als Lesezeichen
Ich nehme an mit "Prüfung ob die Options einen Wert haben" meinst du, ob $options['value'] existiert und gleichzeitig nicht leer ist.

Versuch mal, die Zeile

<?php if ($option['type'] == 'option'): ?>

zu ersetzen gegen
<?php if ($option['type'] == 'option' && isset( $option['value'])): ?>