Ergebnis 1 bis 2 von 2

Thema: Formular anpassen / leere Options ausblenden

  1. #1
    Contao-Nutzer
    Registriert seit
    25.09.2013.
    Beiträge
    174

    Standard Formular anpassen / leere Options ausblenden

    Hallo, möchte gerne Trilobit - Konstanten als Radio in mein Formular einbinden. Das klappt auch soweit, nur benötige ich nun eine Prüfung, ob ein Value vorhanden ist, damit dann leere Radios nicht angezeigt werden. Wie kann ich hier eine IF-ELSE Abfrage einbauen. Kann da jemand helfen?

    PHP-Code:
    <?php $this->extend('form_row'); ?>

    <?php $this->block('field'); ?>
      <fieldset id="ctrl_<?= $this->id ?>" class="radio_container<?php if ($this->class) echo ' ' $this->class?>">

        <?php if ($this->label): ?>
          <legend>
            <?php if ($this->mandatory): ?>
              <span class="invisible"><?= $this->mandatoryField ?> </span><?= $this->label ?><span class="mandatory">*</span>
            <?php else: ?>
              <?= $this->label ?>
            <?php endif; ?>
          </legend>
        <?php endif; ?>

        <?php if ($this->hasErrors()): ?>
          <p class="error"><?= $this->getErrorAsString() ?></p>
        <?php endif; ?>

        <?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; ?>

      </fieldset>
    <?php $this->endblock(); ?>
    Um es noch einmal zusammen zu fassen:

    1. Eingabe einer Konstanten (für den Kunden maximal 5 möglich)
    2. Felder als Radio-Options im Formular (5 mögliche Options vorbelegt)
    3. Felder ohne Wert sollen nicht im Formular angezeigt werden (falls doch nur 3 vom Kunden benutzt werden) -> wenn value="<?= $option['value'] ?> leer ist soll diese nicht als Option angezeigt werden.

    Es geht hier um Punkt 3, Infos im Bild

    formular-variablen.jpg
    Geändert von Bernator (14.04.2020 um 14:21 Uhr)

  2. #2
    Contao-Nutzer
    Registriert seit
    25.09.2013.
    Beiträge
    174

    Standard replaceInsertTags war die Lösung

    Habe knapp 20 Stunden daran herumgeschraubt....bis ich die Problematik mit InsertTags und PHP erkannt habe. Das Template ist jetzt entsprechend mit replaceInsertTags angepasst und fragt den Wert "label" ab.

    PHP-Code:
    <?php if ($option['type'] == 'option'): ?>
          
     <?php  $option['value'] = \Controller::replaceInsertTags($option['value']) ?>  
     <?php  $option['label'] = \Controller::replaceInsertTags($option['label']) ?> 

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

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •