How to get invalid feedback for file upload

Hey there,

I am currently working on a form that will also have an upload function.
I am using the Cookbook article Forms with attachments | Kirby CMS as a basis.

So far, almost everything is clear to me.

Unfortunately, I am unable to assign the status ‘invalid’ to the input field ‘file’ in the event of an error with the corresponding feedback.

This is the part of form.php:

…
<div class="col-12 mt-4">
  <label class="form-label text_sm f_600" for="file">Daten hochladen <abbr title="required">*</abbr></label>
  <input aria-describedby="file-invalid" class="form-control<?php if (isset($alert['file'])): ?> is-invalid<?php endif ?>" id="file" name="file[]" type="file" multiple>
  <div id="file-invalid" class="invalid-feedback text_sm"><?= isset($alert['file']) ? html($alert['file']) : '' ?></div>
</div>
…

I have already tried:

<?php if (isset($alert['file[]'])): ?>
<?php if (isset($alert['file[]'])): ?>
…
<?php if (isset($alert['attachments'])): ?>
<?php if (isset($alert['attachments[]'])): ?>
…
<?php if (isset($alert['uploads'])): ?>
<?php if (isset($alert['uploads[]'])): ?>
…
<?php if (isset($alert['upload'])): ?>
<?php if (isset($alert['upload[]'])): ?>
…
<?php if (isset($alert[$attachments])): ?>
<?php if (isset($alert[$upload])): ?>
<?php if (isset($alert[$uploads])): ?>

The controller is pretty much the same as in the article. I haven’t changed anything with regard to file uploads.

<?php
return function($kirby, $page) {

    if ($kirby->request()->is('POST') && get('submit')) {

        $alert      = null;
        $attachments = [];

        if (empty(get('website')) === false) {
            go($site->url());
            exit;
        }

        $data = [
            'name'        => get('name'),
            'nachname'    => get('nachname'),
            'email'       => get('email'),
            'phone'       => get('phone'),
            'bday'        => get('bday'),
            'geburtsort'  => get('geburtsort'),
            'street'      => get('street'),
            'hausnummer'  => get('hausnummer'),
            'plz'         => get('plz'),
            'ort'         => get('Ort'),
            'message'     => get('message')
        ];

        $rules = [
            'name'        => ['required', 'min' => 3],
            'nachname'    => ['required', 'min' => 3],
            'email'       => ['required', 'email'],
            'phone'       => ['required'],
            'bday'        => ['required'],
            'geburtsort'  => [],
            'street'      => ['required', 'min' => 3],
            'hausnummer'  => ['required'],
            'plz'         => ['required'],
            'ort'         => ['required', 'min' => 3],
            'message'     => [],
        ];

        $messages = [
            'name'        => 'Bitte geben Sie Ihren Vornamen ein.',
            'nachname'    => 'Bitte geben Sie Ihren Nachnamen ein.',
            'email'       => 'Bitte geben Sie eine gültige E-Mail Adresse ein.',
            'phone'       => 'Bitte geben Sie Ihre Telefonnummer ein.',
            'bday'        => 'Bitte geben Sie Ihr Geburtsdatum ein.',
            'geburtsort'  => '',
            'street'      => 'Bitte geben Sie Ihre Straße ein.',
            'hausnummer'  => 'Bitte geben Sie Ihre Hausnummer ein.',
            'plz'         => 'Bitte geben Sie Ihre Postleitzahl ein.',
            'ort'         => 'Bitte geben Sie Ihren Wohnort ein.',
            'message'     => ''
        ];

        if ($invalid = invalid($data, $rules, $messages)) {
            $alert = $invalid;
        }

        $uploads = $kirby->request()->files()->get('file');

        if (count($uploads) > 3) {
            $alert[] = 'Sie können maximal 3 PDFs hochladen.';
        }

        foreach ($uploads as $upload) {
            if ($upload['error'] === 4) {
                $alert[] = 'Sie müssen mindestens ein PDF hochladen.';
            } elseif ($upload['error'] !== 0) {
                $alert[] = 'Die Datei konnte nicht hochgeladen werden.';
            } elseif ($upload['size'] > 5000000)  {
                $alert[] = $upload['name'] . ' is larger than 5 MB';
            } elseif ($upload['type'] !== 'application/pdf') {
                $alert[] = $upload['name'] . ' Ist kein PDF.';
            } else {
                $name     = $upload['tmp_name'];
                $tmpName  = pathinfo($name);
                $filename = $tmpName['dirname']. '/'. F::safeName($upload['name']);

                if (rename($upload['tmp_name'], $filename)) {
                    $name = $filename;
                }
                $attachments[] = $name;
            }
        }

        if (empty($alert)) {
            try {
              $kirby->email([
                  'template' => 'email',
                  'from'     => 'noreply@….de',
                  'replyTo'  => $data['email'],
                  'to'       => '…@….de',
                  'subject'  => '…',
                  'data'              => [
                      'name'          => esc($data['name']),
                      'nachname'      => esc($data['nachname']),
                      'email'         => esc($data['email']),
                      'phone'         => esc($data['phone']),
                      'bday'          => esc($data['bday']),
                      'geburtsort'    => esc($data['geburtsort']),
                      'street'        => esc($data['street']),
                      'hausnummer'    => esc($data['hausnummer']),
                      'plz'           => esc($data['plz']),
                      'ort'           => esc($data['ort']),
                      'message'       => esc($data['message']),
                      'attachments'   => $attachments

                  ],
                  'attachments' => $attachments
              ]);
            } catch (Exception $error) {
              if (option('debug')):
                 $alert['error'] = 'The form could not be sent: <strong>' . $error->getMessage() . '</strong>';
             else:
                 $alert['error'] = 'The form could not be sent!';
             endif;
            }

            if (empty($alert) === true) {
                $kirby->session()->set([
                    'name' => esc($data['name'])
                ]);

                go('success');
            }
        }
    }

    return [
        'alert' => $alert ?? null,
        'data'   => $data   ?? false,
    ];
};

Thank you for reading this far!
I hope someone can give me a hint or even solve the problem.

Best regards
Martin

While $invalid returns a associative array, in the controller we add the errors related to files via numeric keys.

If would be better to do it like this:

$fileErrors = [];

foreach ($uploads as $upload) {
    if ($upload['error'] === 4) {
        $fileErrors[] = 'Sie müssen mindestens ein PDF hochladen.';
    } elseif {} // etc.
}

if (count($fileErrors)) {
  $alert['fileErrors'] = $fileErrors;
}

Then you can check if you have that key in the array in your template.

1 Like

Hey there,

thank you very much for your hints but unfortunately, I can’t get it to work.

I got this error:


This is the controller now:

…
$alert      = null;
$attachments = [];
$fileErrors = [];

if (empty(get('website')) === false) {go($site->url()); exit;}

$data = […]; $rules = […]; $messages = […];

if ($invalid = invalid($data, $rules, $messages)) {$alert = $invalid;}

$uploads = $kirby->request()->files()->get('file');

if (count($uploads) > 3) {$alert[] = 'Sie können maximal 3 PDFs hochladen.';}

foreach ($uploads as $upload) {
     if ($upload['error'] === 4)                     {$fileErrors[] = 'Sie müssen mindestens ein PDF hochladen.';}
     elseif ($upload['error'] !== 0)                 {$fileErrors[] = 'Die Datei konnte nicht hochgeladen werden.';}
     elseif ($upload['size'] > 5000000)              {$fileErrors[] = $upload['name'] . ' is larger than 5 MB';}
     elseif ($upload['type'] !== 'application/pdf')  {$fileErrors[] = $upload['name'] . ' Ist kein PDF.';}
      else {$name = $upload['tmp_name']; $tmpName  = pathinfo($name); $filename = $tmpName['dirname']. '/'. F::safeName($upload['name']);
           if (rename($upload['tmp_name'], $filename)) {$name = $filename;} $attachments[] = $name;}
}

        if (count($fileErrors) {$alert['fileErrors'] = $fileErrors;}

        if (empty($alert)) {try …
     

Also I don’t know how to archive these keys to my input field ;/

<?= isset($fileErrors['???']) ? html($fileErrors['???']) : '' ?>
…
<?php if (isset($fileErrors['???'])): ?> is-invalid<?php endif ?>

Well maybe you can help once more^^

There’s a parenthesis missing to close the if statement

1 Like

The here, you have to check if isset($alert['fileErrors']), because you are not passing $fileErrors, but $alert to the template.

1 Like

Slowly but surely, something is happening :wink:

First: This works perfectly. Now I can work with the Bootstrap invald-classes.

<label for="file">
   Upload <abbr title="required">*</abbr>
</label>

   <input  aria-describedby="file-invalid"
           class="<?php if (isset($alert['fileErrors'])): ?> is-invalid<?php endif ?>" 
           id="file"
           name="file[]"
           type="file"
           multiple
   >

<div id="file-invalid" class="invalid-feedback">
   <?php if (isset($alert['fileErrors'])):
      foreach ($alert['fileErrors'] as $message):
         echo $message;
      endforeach;
   endif; ?>
</div>

Now I get error while loop trough all other errors ;/

<?php if ($alert): $anchor = "#cp_career_form";?>
<script type="text/javascript">window.location.hash = "<?= $anchor ; ?>";</script>
<div class="form_alerts f_600 p-3 p-md-4 mb-4">
  <h3 class="dr f_600">Warnmeldungen</h3>
  <ul class="m-0 p-0">
  <?php foreach ($alert as $message): ?><li><i class="bi bi-exclamation-diamond"></i> <?php echo $message ?></li><?php endforeach ?>
  </ul>
</div>
<?php endif ?>

The problem seems to be…

<?php foreach ($alert as $message): ?>… <?php echo $message …

The Error:

I don’t like to get on other people’s nerves, especially when it’s because of my lack of knowledge.

But I feel it… we’re very close :slight_smile:

Best regards
Martin

Looks like atleaset one of the values of $messageis an Array which you cant just echo since it is not a string. That is what is meant by “Array to string conversion“.

If you var_dump $alert before that foreach loop, you will see what is actually the value and type of that variables contents and then you can can alter the foreach loop accordingly to handle alerts that are just a plain string or an array with multiple items inside. You might have to remove your existing echo $message to prevent the whoops page showing up in order to see the var_dump.

<?php var_dump($alert) ?>
1 Like

Well, yes, $alert['fileErrors'] is an array, as we defined it in the controller. But wait, since it can be only one of multiple errors, we can make it a simple message. Sorry, should have been more attentive.

$fileError = ''; // note I make this singular

if ($upload['error'] === 4) {
    $fileError = 'Sie müssen mindestens ein PDF hochladen.';
} 
// etc.

// Then later

if (empty($fileError) === false) {
   $alert['fileError'] = $fileError;
}
1 Like

Thank you so much!

Everything is working exactly as I envisioned.

If anyone needs a form with upload, checkbox, and radio buttons, along with their valid/invalid feedback, here’s the source code.

controller:

<?php return function($kirby, $page) {

    if ($kirby->request()->is('POST') && get('submit')) {

        $alert      = null;
        $attachments = [];
        $fileErrors = [];

        if (empty(get('website')) === false) {go($site->url()); exit;}

        $data = [
            'name'        => get('name'),
            'nachname'    => get('nachname'),
            'email'       => get('email'),
            'phone'       => get('phone'),
            'bday'        => get('bday'),
            'geburtsort'  => get('geburtsort'),
            'street'      => get('street'),
            'hausnummer'  => get('hausnummer'),
            'plz'         => get('plz'),
            'ort'         => get('Ort'),
            'execute'       => get('execute'),
            'execute_other' => get('execute_other'),
            'qualifikation' => get('qualifikation'),
            'qualifikation_other' => get('qualifikation_other'),
            'message'     => get('message'),
        ];

        $rules = [
            'name'        => ['required', 'min' => 3],
            'nachname'    => ['required', 'min' => 3],
            'email'       => ['required', 'email'],
            'phone'       => ['required'],
            'bday'        => ['required'],
            'geburtsort'  => [],
            'street'      => ['required', 'min' => 3],
            'hausnummer'  => ['required'],
            'plz'         => ['required'],
            'ort'         => ['required', 'min' => 3],
            'execute'           => ['required'],
            'execute_other'     => [],
            'qualifikation' => ['required'],
            'qualifikation_other'     => [],
            'message'     => [],
        ];

        $messages = [
            'name'        => 'Bitte geben Sie Ihren Vornamen ein.',
            'nachname'    => 'Bitte geben Sie Ihren Nachnamen ein.',
            'email'       => 'Bitte geben Sie eine gültige E-Mail Adresse ein.',
            'phone'       => 'Bitte geben Sie Ihre Telefonnummer ein.',
            'bday'        => 'Bitte geben Sie Ihr Geburtsdatum ein.',
            'geburtsort'  => '',
            'street'      => 'Bitte geben Sie Ihre Straße ein.',
            'hausnummer'  => 'Bitte geben Sie Ihre Hausnummer ein.',
            'plz'         => 'Bitte geben Sie Ihre Postleitzahl ein.',
            'ort'         => 'Bitte geben Sie Ihren Wohnort ein.',
            'execute'     => 'Bitte geben Sie Ihre bevorzugten Tätigkeiten ein.',
            'execute_other'     => '',
            'qualifikation'     => 'Bitte geben Sie Ihre Qualifikation an.',
            'qualifikation_other'     => '',
            'message'     => ''
        ];

        if ($invalid = invalid($data, $rules, $messages)) {$alert = $invalid;}

        $uploads = $kirby->request()->files()->get('file');

        if (count($uploads) > 3) {$alert[] = 'Sie können maximal 3 PDFs hochladen.';}

        foreach ($uploads as $upload)
        {
          $fileError = '';
          if ($upload['error'] === 4)                     {$fileError = 'Sie müssen mindestens ein PDF hochladen.';}
          elseif ($upload['error'] !== 0)                 {$fileError = 'Die Datei konnte nicht hochgeladen werden.';}
          elseif ($upload['size'] > 5000000)              {$fileError = $upload['name'] . ' is larger than 5 MB';}
          elseif ($upload['type'] !== 'application/pdf')  {$fileError = $upload['name'] . ' Ist kein PDF.';}
          else {$name = $upload['tmp_name']; $tmpName  = pathinfo($name); $filename = $tmpName['dirname']. '/'. F::safeName($upload['name']);
              if (rename($upload['tmp_name'], $filename)) {$name = $filename;} $attachments[] = $name;
              }
        }

        if (empty($fileError) === false) {$alert['fileError'] = $fileError;}


      //  if (count($fileErrors)) {$alert['fileErrors'] = $fileErrors;}

        if (empty($alert)) {try
          {
              $kirby->email([
                  'template' => 'email',
                  'from'     => 'noreply@xyz.de',
                  'replyTo'  => $data['email'],
                  'to'       => 'xyz@xyz.de',
                  'subject'  => esc($data['name']) . ' hat eine Bewerbung eingereicht',
                  'data'              => [
                      'name'          => esc($data['name']),
                      'nachname'      => esc($data['nachname']),
                      'email'         => esc($data['email']),
                      'phone'         => esc($data['phone']),
                      'bday'          => esc($data['bday']),
                      'geburtsort'    => esc($data['geburtsort']),
                      'street'        => esc($data['street']),
                      'hausnummer'    => esc($data['hausnummer']),
                      'plz'           => esc($data['plz']),
                      'ort'           => esc($data['ort']),

                      'execute'       => $data['execute'],
                      'execute_other' => esc($data['execute_other']),

                      'qualifikation' => $data['qualifikation'],
                      'qualifikation_other' => esc($data['qualifikation_other']),

                      'message'       => esc($data['message']),
                      'attachments'   => $attachments

                  ],
                  'attachments' => $attachments
              ]);
            } catch (Exception $error) {
              if (option('debug')):
                 $alert['error'] = 'The form could not be sent: <strong>' . $error->getMessage() . '</strong>';
             else:
                 $alert['error'] = 'The form could not be sent!';
             endif;
            }

            if (empty($alert) === true) {
                $kirby->session()->set([
                    'name' => esc($data['name'])
                ]);

                go('success');
            }
        }
    }

    return [
        'alert' => $alert ?? null,
        'data'   => $data   ?? false,
    ];
};

form:

<?php if ($alert): $anchor = "#cp_career_form";?>
<script type="text/javascript">window.location.hash = "<?= $anchor ; ?>";</script>
<div class="form_alerts f_600 p-3 p-md-4 mb-4">
  <h3 class="dr f_600">Warnmeldungen</h3>
  <ul class="m-0 p-0">
  <?php foreach (($alert) as $message): ?><li><i class="bi bi-exclamation-diamond"></i> <?php echo $message ?></li><?php endforeach ?>
  </ul>
</div>
<?php endif ?>

<form method="post" action="<?= $page->url() ?>" enctype="multipart/form-data">
<div class="row">

    <div class="honeymoon col-12">
        <label class="form-label f_600" for="website">Website <abbr title="required">*</abbr></label>
        <input aria-describedby="website-invalid" type="website" id="website" name="website">
        <div id="website-invalid" class="invalid-feedback text_sm">Honey Honey Honey</div>
    </div>

    <div class="col-12 col-md-6">
        <label class="form-label f_600" for="name">Vorname <abbr title="required">*</abbr></label>
        <input aria-describedby="name-invalid" class="form-control<?php if (isset($alert['name'])): ?> is-invalid<?php endif ?>" type="text" id="name" name="name" value="<?= $data['name'] ?? null ?>">
        <div id="name-invalid" class="invalid-feedback text_sm"><?= isset($alert['name']) ? html($alert['name']) : '' ?></div>
    </div>

    <div class="col-12 col-md-6">
        <label class="form-label f_600" for="nachname">Nachname <abbr title="required">*</abbr></label>
        <input aria-describedby="nachname-invalid" class="form-control<?php if (isset($alert['nachname'])): ?> is-invalid<?php endif ?>" type="text" id="nachname" name="nachname" value="<?= $data['nachname'] ?? null ?>">
        <div id="nachname-invalid" class="invalid-feedback text_sm"><?= isset($alert['nachname']) ? html($alert['nachname']) : '' ?></div>
    </div>

    <div class="col-12 col-md-6 mt-4">
      <label class="form-label f_600" for="email">Email <abbr title="required">*</abbr></label>
      <input aria-describedby="email-invalid" class="form-control<?php if (isset($alert['email'])): ?> is-invalid<?php endif ?>" type="email" id="email" name="email" value="<?= $data['email'] ?? null ?>">
      <div id="email-invalid" class="invalid-feedback text_sm"><?= isset($alert['email']) ? html($alert['email']) : '' ?></div>
    </div>

    <div class="col-12 col-md-6 mt-4">
      <label class="form-label f_600" class="form-label" for="phone">Telefonnummer: <abbr title="required">*</abbr></label>
      <input aria-describedby="phone-invalid" class="form-control<?php if (isset($alert['phone'])): ?> is-invalid<?php endif ?>" type="tel" id="phone" name="phone" value="<?= $data['phone'] ?? null ?>">
      <div id="phone-invalid" class="invalid-feedback text_sm"><?= isset($alert['phone']) ? html($alert['phone']) : '' ?></div>
    </div>

    <div class="col-12 col-md-6 mt-4">
      <label class="form-label f_600" for="bday">Geburtsdatum <abbr title="required">*</abbr></label>
      <input aria-describedby="bday-invalid" class="form-control<?php if (isset($alert['bday'])): ?> is-invalid<?php endif ?>" type="date" id="bday" name="bday" value="<?= $data['bday'] ?? null ?>">
      <div id="bday-invalid" class="invalid-feedback text_sm"><?= isset($alert['bday']) ? html($alert['bday']) : '' ?></div>
    </div>

    <div class="col-12 col-md-6 mt-4">
        <label class="form-label f_600" for="geburtsort">Geburtsort</label>
        <input class="form-control" type="text" id="geburtsort" name="geburtsort" value="<?= $data['geburtsort'] ?? null ?>">
    </div>

    <div class="col-12 col-md-8 mt-4">
        <label class="form-label f_600" for="street">Straße <abbr title="required">*</abbr></label>
        <input aria-describedby="street-invalid" class="form-control<?php if (isset($alert['street'])): ?> is-invalid<?php endif ?>" type="text" id="street" name="street" value="<?= $data['street'] ?? null ?>">
        <div id="street-invalid" class="invalid-feedback text_sm"><?= isset($alert['street']) ? html($alert['street']) : '' ?></div>
    </div>

    <div class="col-12 col-md-4 mt-4">
        <label class="form-label f_600" for="hausnummer">Hausnummer <abbr title="required">*</abbr></label>
        <input aria-describedby="hausnummer-invalid" class="form-control<?php if (isset($alert['hausnummer'])): ?> is-invalid<?php endif ?>" type="number" id="hausnummer" name="hausnummer" value="<?= $data['hausnummer'] ?? null ?>">
        <div id="hausnummer-invalid" class="invalid-feedback text_sm"><?= isset($alert['hausnummer']) ? html($alert['hausnummer']) : '' ?></div>
    </div>

    <div class="col-12 col-md-4 mt-4">
        <label class="form-label f_600" for="plz">PLZ <abbr title="required">*</abbr></label>
        <input aria-describedby="plz-invalid" class="form-control<?php if (isset($alert['plz'])): ?> is-invalid<?php endif ?>" type="number" id="plz" name="plz" value="<?= $data['plz'] ?? null ?>">
        <div id="plz-invalid" class="invalid-feedback text_sm"><?= isset($alert['plz']) ? html($alert['plz']) : '' ?></div>
    </div>

    <div class="col-12 col-md-8 mt-4">
        <label class="form-label f_600" for="street">Ort <abbr title="required">*</abbr></label>
        <input aria-describedby="ort-invalid" class="form-control<?php if (isset($alert['ort'])): ?> is-invalid<?php endif ?>" type="text" id="ort" name="ort" value="<?= $data['ort'] ?? null ?>">
        <div id="ort-invalid" class="invalid-feedback text_sm"><?= isset($alert['ort']) ? html($alert['ort']) : '' ?></div>
    </div>

    <div class="col-12 col-md-8 mt-4">
      <p class="f_600 mb-1 mt-1">Bevorzugte Tätigkeiten <abbr title="required">*</abbr></p>

      <div class="form-check">
        <input class="form-check-input<?php if (isset($alert['execute'])): ?> is-invalid<?php endif ?>" type="checkbox" id="execute1" name="execute[]" value="Pflege" <?= isset($data['execute']) && in_array('Pflege', $data['execute']) ? 'checked' : '' ?>>
        <label class="form-check-label" for="execute1">Pflege</label>
      </div>

      <div class="form-check">
        <input class="form-check-input<?php if (isset($alert['execute'])): ?> is-invalid<?php endif ?>" type="checkbox" id="execute2" name="execute[]" value="Hauswirtschaft" <?= isset($data['execute']) && in_array('Hauswirtschaft', $data['execute']) ? 'checked' : '' ?>">
        <label class="form-check-label" for="execute2">Hauswirtschaft</label>
      </div>

      <div class="form-check">
        <input aria-describedby="execute-invalid" class="form-check-input<?php if (isset($alert['execute'])): ?> is-invalid<?php endif ?>" type="checkbox" id="execute3" name="execute[]" value="Sonstiges" <?= isset($data['execute']) && in_array('Sonstiges', $data['execute']) ? 'checked' : '' ?>">
        <label class="form-check-label" for="execute3">Sonstiges</label>
        <!--last one get invalid feedback cause of diff area labels-->
        <div id="execute-invalid" class="invalid-feedback text_sm"><?= isset($alert['execute']) ? html($alert['execute']) : '' ?></div>
      </div>
    </div>

    <div class="col-12 mt-2 execute_other mb-2">
        <textarea placeholder="Beschreiben Sie Ihre bevorzugten Tätigkeiten…" class="form-control" id="execute_other" name="execute_other"><?= $data['execute_other']?? null ?></textarea>
    </div>

<div class="col-12 col-md-8 mt-4">
  <p class="f_600 mb-1 mt-1">Ihre Qualifikation <abbr title="required">*</abbr></p>
  <?php $value = $data['qualifikation']?? '' ?>

  <div class="form-check">
    <input type="radio" name="qualifikation" id="qualifikation1" value="Pflegefachkraft" class="checkquali form-check-input<?php if (isset($alert['qualifikation'])): ?> is-invalid<?php endif ?>" <?php e($value=='Pflegefachkraft', 'checked')?>>
    <label class="form-check-label" for="qualifikation1">Pflegefachkraft</label>
  </div>

  <div class="form-check">
    <input type="radio" name="qualifikation" id="qualifikation2" value="Pflegekraft_mit_einjaehriger_Ausbildung" class="checkquali form-check-input<?php if (isset($alert['qualifikation'])): ?> is-invalid<?php endif ?>" <?php e($value=='Pflegekraft_mit_einjaehriger_Ausbildung', 'checked')?>>
    <label class="form-check-label" for="qualifikation2">Pflegekraft mit einjähriger Ausbildung</label>
  </div>

  <div class="form-check">
    <input type="radio" name="qualifikation" id="qualifikation3" value="Pflegekraft_mit_Pflegebasiskurs" class="checkquali form-check-input<?php if (isset($alert['qualifikation'])): ?> is-invalid<?php endif ?>" <?php e($value=='Pflegekraft_mit_Pflegebasiskurs', 'checked')?>>
    <label class="form-check-label" for="qualifikation3">Pflegekraft mit Pflegebasiskurs</label>
  </div>

  <div class="form-check">
    <input type="radio" name="qualifikation" id="qualifikation4" value="Pflegekraft_ungelernt" class="checkquali form-check-input<?php if (isset($alert['qualifikation'])): ?> is-invalid<?php endif ?>" <?php e($value=='Pflegekraft_ungelernt', 'checked')?>>
    <label class="form-check-label" for="qualifikation4">Pflegekraft ungelernt</label>
  </div>

  <div class="form-check qualifikation5">
    <input aria-describedby="qualifikation-invalid" type="radio" name="qualifikation" id="qualifikation5" value="Andere_Qualifikation" class="checkquali form-check-input<?php if (isset($alert['qualifikation'])): ?> is-invalid<?php endif ?>" <?php e($value=='Andere_Qualifikation', 'checked')?>>
    <label class="form-check-label" for="qualifikation5">Andere Qualifikation</label>

    <!--last one get invalid feedback cause of diff area labels-->
    <div id="qualifikation-invalid" class="invalid-feedback text_sm"><?= isset($alert['qualifikation']) ? html($alert['qualifikation']) : '' ?></div>
  </div>

</div>


<div class="col-12 mt-2 qualifikation_other mb-2">
    <textarea placeholder="Beschreiben Sie Ihre Qualifikationen…" class="form-control" id="qualifikation_other" name="qualifikation_other"><?= $data['qualifikation_other']?? null ?></textarea>
</div>



    <div class="col-12 mt-4">
      <label class="form-label f_600" for="file">Bewerbungsunterlagen hochladen <abbr title="required">*</abbr></label>
      <input aria-describedby="file-invalid" class="form-control<?php if (isset($alert['fileError'])): ?> is-invalid<?php endif ?>" id="file" name="file[]" type="file" multiple>
      <span class="help text_sm">Max. 3 PDF Dateien (max. Dateigröße 5MB)</span>
      <div id="file-invalid" class="invalid-feedback text_sm">
        <?= isset($alert['fileError']) ? html($alert['fileError']) : '' ?>
      </div>
    </div>


    <div class="col-12 mt-4">
        <label class="form-label f_600" for="message">Nachricht an uns…</label>
        <textarea placeholder="Haben Sie besondere Wünsche, wie Arbeitszeit, Wochenstunden etc. …" class="form-control" id="message" name="message"><?= $data['message']?? null ?></textarea>
    </div>

    <div class="col-12 mt-4">
      <button class="btn btn-secondary btn-lg" type="button submit" name="submit" id="submit" value="Submit">Senden</button>
    </div>

</div>
</form>

Conditional fields:

<?php if ($page->intendedTemplate()->name() === 'your-template-name') : ?>
  <?= js(['assets/js/conditional-field.js','@auto']) ?>
  <script>
  new ConditionalField({
    control: '#execute3',
    visibility: {
     'on': '.execute_other',
    }
  });

  new ConditionalField({
    control: '.checkquali',
    visibility: {
     'Andere_Qualifikation': '.qualifikation_other',
    }
  });
  </script>
<?php endif ?>

Regards
Martin

1 Like