/**
 * Returns the view of a form field.
 *
 * @param string $form_id A form ID.
 * @param string $field   A field.
 *
 * @return string (X)HTML.
 *
 * @global array  The paths of system files and folders.
 * @global array  The configuration of the core.
 * @global string The (X)HTML fragment for insertion into the HEAD element.
 */
function Advancedform_displayField($form_id, $field)
{
    global $pth, $plugin_cf, $hjs;
    $pcf = $plugin_cf['advancedform'];
    $o = '';
    $name = 'advfrm-' . $field['field'];
    $id = 'advfrm-' . $form_id . '-' . $field['field'];
    $props = explode("¦", $field['props']);
    $is_select = Advancedform_isSelect($field);
    $is_real_select = Advancedform_isRealSelect($field);
    $is_multi = Advancedform_isMulti($field);
    // Add Class
    if (isset($field['class']) && !empty($field['class'])) {
        $class = ' class="' . $field['class'] . '"';
    } else {
        $class = '';
    }
    if ($is_select) {
        $brackets = $is_multi ? '[]' : '';
        if ($is_real_select) {
            $size = array_shift($props);
            $size = empty($size) ? '' : ' size="' . $size . '"';
            $multi = $is_multi ? ' multiple="multiple"' : '';
            $o .= '<select id="' . $id . '" name="' . $name . $brackets . '"' . $size . $multi . $class . '>';
        } else {
            $orient = array_shift($props) ? 'vert' : 'horz';
        }
        foreach ($props as $i => $opt) {
            $opt = explode("●", $opt);
            if (count($opt) > 1) {
                $f = true;
                $opt = $opt[1];
            } else {
                $f = false;
                $opt = $opt[0];
            }
            if (function_exists('advfrm_custom_field_default')) {
                $cust_f = advfrm_custom_field_default($form_id, $field['field'], $opt, isset($_POST['advfrm']));
            }
            if (isset($cust_f)) {
                $f = $cust_f;
            } else {
                $f = isset($_POST['advfrm']) && isset($_POST[$name]) && ($is_multi ? in_array($opt, array_map('stsl', $_POST[$name])) : stsl($_POST[$name]) == $opt) || !isset($_POST['advfrm']) && $f;
            }
            $sel = $f ? $is_real_select ? ' selected="selected"' : ' checked="checked"' : '';
            if ($is_real_select) {
                $o .= '<option' . $sel . '>' . Advancedform_hsc($opt) . '</option>';
            } else {
                $o .= '<div class="' . $orient . '"><label>' . tag('input type="' . $field['type'] . '" name="' . $name . $brackets . '" value="' . Advancedform_hsc($opt) . '"' . $sel . $class) . '&nbsp;' . Advancedform_hsc($opt) . '</label></div>';
            }
        }
        if ($is_real_select) {
            $o .= '</select>';
        }
    } else {
        $type = in_array($field['type'], array('file', 'password', 'hidden')) ? $field['type'] : 'text';
        if (function_exists('advfrm_custom_field_default')) {
            $val = advfrm_custom_field_default($form_id, $field['field'], null, isset($_POST['advfrm']));
        }
        if (!isset($val)) {
            $val = isset($_POST[$name]) ? stsl($_POST[$name]) : $props[ADVFRM_PROP_DEFAULT];
        }
        if ($field['type'] == 'textarea') {
            $cols = empty($props[ADVFRM_PROP_COLS]) ? 40 : $props[ADVFRM_PROP_COLS];
            $rows = empty($props[ADVFRM_PROP_ROWS]) ? 4 : $props[ADVFRM_PROP_ROWS];
            $o .= '<textarea id="' . $id . '" name="' . $name . '" cols="' . $cols . '" rows="' . $rows . '"' . $class . '>' . Advancedform_hsc($val) . '</textarea>';
        } elseif ($field['type'] == 'output') {
            $o .= $val;
        } else {
            if ($field['type'] == 'date') {
                $showOn = $pcf['datepicker_icon'] ? 'both' : 'focus';
                $iconPath = $pth['folder']['plugins'] . 'advancedform/images/calendar.png';
                $hjs .= <<<EOS
<script type="text/javascript">/* <![CDATA[ */
jQuery(function() {
    jQuery('.advfrm-mailform form[name="{$form_id}"] input[name="{$name}"]')
        .datepicker({
            showOn: "{$showOn}",
            buttonImage: "{$iconPath}",
            buttonImageOnly: true
        })
});
/* ]]> */</script>

EOS;
            }
            $size = $field['type'] == 'hidden' || empty($props[ADVFRM_PROP_SIZE]) ? '' : ' size="' . $props[ADVFRM_PROP_SIZE] . '"';
            $maxlen = in_array($field['type'], array('hidden', 'file')) || empty($props[ADVFRM_PROP_MAXLEN]) ? '' : ' maxlength="' . $props[ADVFRM_PROP_MAXLEN] . '"';
            if ($field['type'] == 'file' && !empty($props[ADVFRM_PROP_MAXLEN])) {
                $o .= tag('input type="hidden" name="MAX_FILE_SIZE" value="' . $props[ADVFRM_PROP_MAXLEN] . '"');
            }
            if ($field['type'] == 'file') {
                $value = '';
                $accept = ' accept="' . Advancedform_hsc(Advancedform_prefixFileExtensionList($val)) . '"';
            } else {
                $value = ' value="' . Advancedform_hsc($val) . '"';
                $accept = '';
            }
            $o .= tag('input type="' . $type . '" id="' . $id . '" name="' . $name . '"' . $value . $accept . $size . $maxlen . $class);
        }
    }
    return $o;
}
Пример #2
0
 /**
  * Renders a non select field.
  *
  * @return string (X)HTML.
  */
 protected function renderNonSelectField()
 {
     $o = '';
     if (function_exists('advfrm_custom_field_default')) {
         $val = advfrm_custom_field_default($this->form, $this->field->getName(), null, isset($_POST['advfrm']));
     }
     if (!isset($val)) {
         $val = isset($_POST[$this->name]) ? stsl($_POST[$this->name]) : $this->field->getDefaultValue();
     }
     if ($this->field->getType() == 'textarea') {
         $cols = $this->field->getColumnCount() ? $this->field->getColumnCount() : 40;
         $rows = $this->field->getRowCount() ? $this->field->getRowCount() : 4;
         $o .= '<textarea id="' . $this->id . '" name="' . $this->name . '" cols="' . $cols . '" rows="' . $rows . '">' . XH_hsc($val) . '</textarea>';
     } elseif ($this->field->getType() == 'output') {
         $o .= $val;
     } else {
         if ($this->field->getType() == 'date') {
             $this->initDatePicker();
         }
         $size = $this->field->getType() == 'hidden' || $this->field->getSize() ? ' size="' . $this->field->getSize() . '"' : '';
         $maxlen = in_array($this->field->getType(), array('hidden', 'file')) || !$this->field->getMaxLength() ? '' : ' maxlength="' . $this->field->getMaxLength() . '"';
         if ($this->field->getType() == 'file' && $this->field->getMaxLength()) {
             $o .= tag('input type="hidden" name="MAX_FILE_SIZE" value="' . $this->field->getMaxLength() . '"');
         }
         if ($this->field->getType() == 'file') {
             $value = '';
             $accept = ' accept="' . XH_hsc($this->prefixFileExtensionList($val)) . '"';
         } else {
             $value = ' value="' . XH_hsc($val) . '"';
             $accept = '';
         }
         $o .= tag('input type="' . $this->getInputElementType() . '" id="' . $this->id . '" name="' . $this->name . '"' . $value . $accept . $size . $maxlen);
     }
     return $o;
 }