Skip to content
Snippets Groups Projects
dynamic-form.tmpl.php 4.23 KiB
Newer Older
<?php
// If the form was removed using the trashcan option, and there was some
// other validation error, don't render the deleted form the second time
if (isset($options['entry']) && $options['mode'] == 'edit'
    && $_POST
    && ($_POST['forms'] && !in_array($options['entry']->getId(), $_POST['forms']))
)
    return;

if (isset($options['entry']) && $options['mode'] == 'edit') { ?>
Peter Rotich's avatar
Peter Rotich committed
    <tr><td style="width:<?php echo $options['width'] ?: 150;?>px;"></td><td></td></tr>
<?php
// Keep up with the entry id in a hidden field to decide what to add and
// delete when the parent form is submitted
if (isset($options['entry']) && $options['mode'] == 'edit') { ?>
    <input type="hidden" name="forms[]" value="<?php
        echo $options['entry']->getId(); ?>" />
<?php } ?>
<?php if ($form->getTitle()) { ?>
Jared Hancock's avatar
Jared Hancock committed
    <tr><th colspan="2">
        <em><strong><?php echo Format::htmlchars($form->getTitle()); ?></strong>:
        <?php echo Format::htmlchars($form->getInstructions()); ?>
<?php if ($options['mode'] == 'edit') { ?>
        <div class="pull-right">
    <?php if ($options['entry']
                && $options['entry']->getForm()->get('type') == 'G') { ?>
            <a href="#" title="Delete Entry" onclick="javascript:
                $(this).closest('tbody').remove();
                return false;"><i class="icon-trash"></i></a>&nbsp;
    <?php } ?>
            <i class="icon-sort" title="Drag to Sort"></i>
        </div>
<?php } ?></em>
Jared Hancock's avatar
Jared Hancock committed
    </th></tr>
    <?php
Jared Hancock's avatar
Jared Hancock committed
    foreach ($form->getFields() as $field) {
            if (!$field->isEditableToStaff())
                continue;
        }
        catch (Exception $e) {
            // Not connected to a DynamicFormField
        }
Jared Hancock's avatar
Jared Hancock committed
        ?>
        <tr><?php if ($field->isBlockLevel()) { ?>
                <td colspan="2">
                <?php
            }
            else { ?>
                <td class="multi-line <?php if ($field->isRequiredForStaff() || $field->isRequiredForClose()) echo 'required';
                ?>" style="min-width:120px;" <?php if ($options['width'])
                    echo "width=\"{$options['width']}\""; ?>>
                <?php echo Format::htmlchars($field->getLocal('label')); ?>:</td>
                <td><div style="position:relative"><?php
            }
            $field->render(); ?>
            <?php if (!$field->isBlockLevel() && $field->isRequiredForStaff()) { ?>
                <span class="error">*</span>
Jared Hancock's avatar
Jared Hancock committed
            <?php
            }
            if (($a = $field->getAnswer()) && $a->isDeleted()) {
                ?><a class="action-button float-right danger overlay" title="Delete this data"
                    href="#delete-answer"
                    onclick="javascript:if (confirm('<?php echo __('You sure?'); ?>'))
                        $.ajax({
                            url: 'ajax.php/form/answer/'
                                +$(this).data('entryId') + '/' + $(this).data('fieldId'),
                            type: 'delete',
                            success: $.proxy(function() {
                                $(this).closest('tr').fadeOut();
                            }, this)
                        });"
                    data-field-id="<?php echo $field->getAnswer()->get('field_id');
                ?>" data-entry-id="<?php echo $field->getAnswer()->get('entry_id');
                ?>"> <i class="icon-trash"></i> </a></div><?php
            }
            if ($a && !$a->getValue() && $field->isRequiredForClose()) {
?><i class="icon-warning-sign help-tip warning"
    data-title="<?php echo __('Required to close ticket'); ?>"
    data-content="<?php echo __('Data is required in this field in order to close the related ticket'); ?>"
/></i><?php
            }
            if ($field->get('hint') && !$field->isBlockLevel()) { ?>
Jared Hancock's avatar
Jared Hancock committed
                <br /><em style="color:gray;display:inline-block"><?php
                    echo Format::htmlchars($field->getLocal('hint')); ?></em>
Jared Hancock's avatar
Jared Hancock committed
            <?php
            }
            foreach ($field->errors() as $e) { ?>
                <br />
                <font class="error"><?php echo Format::htmlchars($e); ?></font>
Jared Hancock's avatar
Jared Hancock committed
            <?php } ?>
Jared Hancock's avatar
Jared Hancock committed
        </tr>
    <?php }
if (isset($options['entry']) && $options['mode'] == 'edit') { ?>