Skip to content
Snippets Groups Projects
form.phtml 3.77 KiB
Newer Older
<?php
  $form = $this->form;
  $form->prepare();

  $title = $form->getTitle();
  $title = !empty($title)
    ? $this->transEsc($title) : null;

  $formUrl = $this->url('feedback-form', ['id' => $this->formId]);
  $form->setAttribute('action', $formUrl);
  $form->setAttribute('class', 'dynamic-form');
  $form->setAttribute('method', 'post');

  $help = $form->getHelp();
  $helpPre = $helpPost = null;
  $helpPre = isset($help['pre']) ? $this->translate($help['pre']) : null;
  $helpPost = isset($help['post']) ? $this->translate($help['post']) : null;
?>
<div class="feedback-content">
  <?php if ($title): ?>
    <?php $this->headTitle($title); ?>
    <h1><?=$title?></h1>
  <?php endif; ?>
  <?=$this->flashmessages()?>

  <?php if ($form->showOnlyForLoggedUsers() && !$this->user): ?>
     <div class="form-group">
       <p><?=$this->translate('feedback_login_required')?></p>
       <a href="<?=$this->url('myresearch-userlogin') ?>" class="btn btn-primary" data-lightbox title="Login"><i class="fa fa-sign-in" aria-hidden="true" data-lightbox-onclose="window.location.href='<?=$this->escapeHtmlAttr($formUrl) ?>'"></i> <?=$this->transEsc("Login") ?></a>
    </div>  
  <?php else: ?>
    <?= $this->form()->openTag($form); ?>
    <?php if ($helpPre): ?>
    <div class="form-group">
      <div class="form-info pre">
        <?=$helpPre?>
      </div>
    </div>
    <?php endif ?>

    <?php $currentGroup = null; ?>
    <?php $countElements = count($form->getElements()); $counter = 0 ?>
    <?php foreach($form->getElements() as $el): ?>
        <? $counter++; ?>
        <? if($counter == $countElements) : ?>
            <div class="form-group">
                <input id="confirmPrivacy" name="confirmPrivacy" type="checkbox" class="margin-r-2" required>
                <label for="confirmPrivacy">
                    <?=
                    $this->translate(
                        'email_contact_policy',
                        ['%%policy_link%%' => '<a target="_blank" href="'. $this->url('fid/user/policy') . '">' . $this->transEsc('fid::policy') . '</a>']
                    );
                    ?>*
                </label>
            </div>
        <?php endif ?>
        <?php


        $formElement = $form->get($el['name']);

        // Group form elements into field sets
        $handleGroup = $group = null;
        if (isset($el['group']) && !empty($el['group'])) {
            $group = $el['group'];
        }
        if ($group && $currentGroup === null) {
            $handleGroup = 'open';
            $currentGroup = $group;
        } elseif ($currentGroup && !$group) {
            $handleGroup = 'close';
            $currentGroup = null;
        } elseif ($currentGroup !== $group) {
            $handleGroup = 'openAndClose';
            $currentGroup = $group;
        }
        ?>

        <?php if (in_array($handleGroup, ['close', 'openAndClose'])): ?>
          </div>
        <?php endif ?>
        <?php if (in_array($handleGroup, ['open', 'openAndClose'])): ?>
          <div class="field-set">
        <?php endif ?>

        <div class="form-group">
        <?php if (!empty($el['help'])): ?>
          <p class="info"><?= $this->transEsc($el['help']) ?></p>
        <?php endif ?>
        <?php if ($el['type'] !== 'submit'): ?>
          <label for="<?=$this->escapeHtmlAttr($el['name'])?>" class="control-label<?=!empty($el['required']) ? ' required' : ''?>"><?=$this->transEsc($el['label'])?>:</label>
        <?php else: ?>
          <?php if ($helpPost): ?>
            <div class="form-info post">
              <?=$helpPost?>
            </div>
          <?php endif ?>
          <?=$this->recaptcha()->html($this->useRecaptcha) ?>
        <?php endif ?>

        <?= $this->formRow($formElement) ?>
        </div>
  <?php endforeach ?>
  <?= $this->form()->closeTag() ?>
  <?php endif ?>
</div>