<?php $this->extend('block_unsearchable'); ?>

<?php $this->block('content'); ?>

<form<?php if ($this->action): ?> action="<?= $this->action ?>"<?php endif; ?> id="<?= $this->formId ?>" method="post">
<div class="formbody">
    <input type="hidden" name="FORM_SUBMIT" value="<?= $this->formId ?>">
    <input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">

    <?php if ($this->message): ?>
    <p class="<?= $this->mclass ?>"><?= $this->message ?></p>
    <?php endif; ?>

    <?php if (!$this->showChannels): ?>
    <?php foreach ($this->channels as $id=>$title): ?>
    <input type="hidden" name="channels[]" value="<?= $id ?>">
    <?php endforeach; ?>
    <?php endif; ?>

    <div class="widget widget-text mandatory">
        <label for="ctrl_email_<?= $this->id ?>" class="invisible"><?= $this->emailLabel ?></label>
        <input type="text" name="email" id="ctrl_email_<?= $this->id ?>" class="text mandatory" value="<?= $this->email ?>" placeholder="<?= $this->emailLabel ?>" required>
    </div>

    <?php if ($this->showChannels): ?>
    <div class="widget widget-checkbox">
        <fieldset id="ctrl_channels_<?= $this->id ?>" class="checkbox_container">
            <legend class="invisible"><?= $this->channelsLabel ?></legend>
            <?php foreach ($this->channels as $id=>$title): ?>
            <label for="opt_<?= $this->id ?>_<?= $id ?>">
                <input type="checkbox" name="channels[]" id="opt_<?= $this->id ?>_<?= $id ?>" value="<?= $id ?>" class="checkbox"<?php if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)) echo ' checked'; ?>>
                <span><?= $title ?></span>
            </label>
            <?php endforeach; ?>
        </fieldset>
    </div>
    <?php endif; ?>

    <?= $this->captcha ?>

    <div class="widget widget-submit">
        <button type="submit" class="submit"><?= $this->submit ?></button>
    </div>
</div>
</form>

<?php if ($this->hasError): ?>
<script>
    try {
        window.scrollTo(null, parseInt($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 40));
    } catch(e) {}
</script>
<?php endif; ?>

<?php $this->endblock(); ?>
