function wpcf7dtx_dynamictext_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type, 'wpcf7dtx-dynamictext');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['minlength'] = $tag->get_minlength_option();
    if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
        unset($atts['maxlength'], $atts['minlength']);
    }
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $scval = do_shortcode('[' . $value . ']');
    if ($scval != '[' . $value . ']') {
        $value = esc_attr($scval);
    }
    $atts['value'] = $value;
    //echo '<pre>'; print_r( $tag ); echo '</pre>';
    switch ($tag->basetype) {
        case 'dynamictext':
            $atts['type'] = 'text';
            break;
        case 'dynamichidden':
            $atts['type'] = 'hidden';
            break;
        default:
            $atts['type'] = 'text';
            break;
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
예제 #2
0
function quai10_text_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type, 'wpcf7-text');
    if (in_array($tag->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['minlength'] = $tag->get_minlength_option();
    if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
        unset($atts['maxlength'], $atts['minlength']);
    }
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
        $atts['required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['value'] = $value;
    if (wpcf7_support_html5()) {
        $atts['type'] = $tag->basetype;
    } else {
        $atts['type'] = 'text';
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input class="%1$s" %2$s />%3$s', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
예제 #3
0
function wpcf7_number_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    $class .= ' wpcf7-validates-as-number';
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $atts['min'] = $tag->get_option('min', 'signed_int', true);
    $atts['max'] = $tag->get_option('max', 'signed_int', true);
    $atts['step'] = $tag->get_option('step', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['value'] = $value;
    if (wpcf7_support_html5()) {
        $atts['type'] = $tag->basetype;
    } else {
        $atts['type'] = 'text';
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
예제 #4
0
function wpcf7_textarea_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['cols'] = $tag->get_cols_option('40');
    $atts['rows'] = $tag->get_rows_option('10');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['minlength'] = $tag->get_minlength_option();
    if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
        unset($atts['maxlength'], $atts['minlength']);
    }
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $atts['autocomplete'] = $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = empty($tag->content) ? (string) reset($tag->values) : $tag->content;
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', sanitize_html_class($tag->name), $atts, esc_textarea($value), $validation_error);
    return $html;
}
function wpcf7_robottrap_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    // default field name
    if (empty($tag->name)) {
        $tag->name = 'email-verify';
    }
    // per field errors
    $validation_error = wpcf7_get_validation_error($tag->name);
    // add wpcf7 specific classes
    $class = wpcf7_form_controls_class('text');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    /**
     * Robots may look for the word "hidden".
     *
     * @ignore Commented out.
     */
    //$atts['aria-hidden'] = 'true';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    } elseif ('' === $value) {
        $value = $tag->get_default_option();
    }
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['value'] = $value;
    $atts['type'] = 'text';
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %s"><input %s />%s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
예제 #6
0
파일: select.php 프로젝트: crazyyy/octagram
function wpcf7_select_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $defaults = array();
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    $values = $tag->values;
    $labels = $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        $values = array_merge($values, array_values($data));
        $labels = array_merge($labels, array_values($data));
    }
    $empty_select = empty($values);
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $html = '';
    $hangover = wpcf7_get_hangover($tag->name);
    foreach ($values as $key => $value) {
        $selected = false;
        if ($hangover) {
            if ($multiple) {
                $selected = in_array(esc_sql($value), (array) $hangover);
            } else {
                $selected = $hangover == esc_sql($value);
            }
        } else {
            if (!$empty_select && in_array($key + 1, (array) $defaults)) {
                $selected = true;
            }
        }
        $item_atts = array('value' => $value, 'selected' => $selected ? 'selected' : '');
        $item_atts = wpcf7_format_atts($item_atts);
        $label = isset($labels[$key]) ? $labels[$key] : $value;
        $html .= sprintf('<option %1$s>%2$s</option>', $item_atts, esc_html($label));
    }
    if ($multiple) {
        $atts['multiple'] = 'multiple';
    }
    $atts['name'] = $tag->name . ($multiple ? '[]' : '');
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
예제 #7
0
function wpcf7_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $html = '';
    $count = 0;
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = array_merge($defaults, explode('_', $matches[1]));
    }
    $defaults = array_unique($defaults);
    $hangover = wpcf7_get_hangover($tag->name, $multiple ? array() : '');
    foreach ($values as $key => $value) {
        $class = 'wpcf7-list-item';
        $checked = false;
        if ($hangover) {
            if ($multiple) {
                $checked = in_array(esc_sql($value), (array) $hangover);
            } else {
                $checked = $hangover == esc_sql($value);
            }
        } else {
            $checked = in_array($key + 1, (array) $defaults);
        }
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            $item = sprintf('<span class="wpcf7-list-item-label">%1$s</span>&nbsp;<input %2$s />', esc_html($label), $item_atts);
        } else {
            $item = sprintf('<input %2$s />&nbsp;<span class="wpcf7-list-item-label">%1$s</span>', esc_html($label), $item_atts);
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        if (false !== $tabindex) {
            $tabindex += 1;
        }
        $count += 1;
        if (1 == $count) {
            $class .= ' first';
        }
        if (count($values) == $count) {
            // last round
            $class .= ' last';
            if ($free_text) {
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text_atts = array('name' => $free_text_name, 'class' => 'wpcf7-free-text', 'tabindex' => $tabindex ? $tabindex : '');
                if (wpcf7_is_posted() && isset($_POST[$free_text_name])) {
                    $free_text_atts['value'] = wp_unslash($_POST[$free_text_name]);
                }
                $free_text_atts = wpcf7_format_atts($free_text_atts);
                $item .= sprintf(' <input type="text" %s />', $free_text_atts);
                $class .= ' has-free-text';
            }
        }
        $item = '<span class="' . esc_attr($class) . '">' . $item . '</span>';
        $html .= $item;
    }
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
예제 #8
0
파일: hidden.php 프로젝트: jrald1291/atu
function wpcf7_hidden_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type, 'wpcf7-hidden');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $class .= ' wpcf7-hidden';
    if ('hidden*' === $tag->type) {
        $class .= ' wpcf7-validates-as-required';
    }
    $value = (string) reset($tag->values);
    $placeholder = '';
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    $default_value = $tag->get_default_option($value);
    $value = contact_form_7_hidden_fields_fill_post_data($value, $tag);
    // Post data hasn't filled yet. No arrays.
    if ($default_value === $value) {
        $value = contact_form_7_hidden_fields_fill_user_data($value);
    }
    // Arrays get imploded.
    $value = is_array($value) ? implode(apply_filters('wpcf7_hidden_field_implode_glue', ', '), $value) : $value;
    // Make sure we're using a string. Objects get JSON-encoded.
    if (!is_string($value)) {
        $value = json_encode($value);
    }
    $value = apply_filters('wpcf7_hidden_field_value', apply_filters('wpcf7_hidden_field_value_' . $tag->get_id_option(), $value));
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts = array('type' => 'hidden', 'class' => $tag->get_class_option($class), 'id' => $tag->get_id_option(), 'name' => $tag->name, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'placeholder' => $placeholder, 'value' => $value);
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input %1$s />%2$s', $atts, $validation_error);
    return $html;
}
function wpcf7_orders_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (!is_user_logged_in()) {
        return 'Please login first to show orders';
    }
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    // Change order query settings here
    $order_posts = get_posts(array('post_type' => 'shop_order', 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_status' => 'publish', 'numberposts' => -1));
    // Display order options
    $values = array();
    foreach ($order_posts as $order) {
        // Set `values` with order ID & order title
        $values[] = '#' . $order->ID . ' | ' . $order->post_title;
    }
    $values = $values;
    $labels = array_values($values);
    $shifted = false;
    if ($include_blank || empty($values)) {
        array_unshift($labels, '---');
        array_unshift($values, '');
        $shifted = true;
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $html = '';
    $hangover = wpcf7_get_hangover($tag->name);
    foreach ($values as $key => $value) {
        $selected = false;
        if ($hangover) {
            if ($multiple) {
                $selected = in_array(esc_sql($value), (array) $hangover);
            } else {
                $selected = $hangover == esc_sql($value);
            }
        } else {
            if (!$shifted && in_array((int) $key + 1, (array) $defaults)) {
                $selected = true;
            } elseif ($shifted && in_array((int) $key, (array) $defaults)) {
                $selected = true;
            }
        }
        $item_atts = array('value' => $value, 'selected' => $selected ? 'selected' : '');
        $item_atts = wpcf7_format_atts($item_atts);
        $label = isset($labels[$key]) ? $labels[$key] : $value;
        $html .= sprintf('<option %1$s>%2$s</option>', $item_atts, esc_html($label));
    }
    if ($multiple) {
        $atts['multiple'] = 'multiple';
    }
    $atts['name'] = $tag->name . ($multiple ? '[]' : '');
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
예제 #10
0
        $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
        if ($tag->has_option('readonly')) {
            $atts['readonly'] = 'readonly';
        }
        if ($tag->is_required()) {
            $atts['aria-required'] = 'true';
            $atts['required'] = 'true';
        }
        $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
        $value = (string) reset($tag->values);
        if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
            $atts['placeholder'] = $value;
            $value = '';
        }
        $value = $tag->get_default_option($value);
        $value = wpcf7_get_hangover($tag->name, $value);
        $atts['value'] = $value;
        if (wpcf7_support_html5()) {
            $atts['type'] = $tag->basetype;
        } else {
            $atts['type'] = 'text';
        }
        $atts['name'] = $tag->name;
        $atts = wpcf7_format_atts($atts);
        $html = sprintf('<input class="%1$s" %2$s />%3$s', sanitize_html_class($tag->name), $atts, $validation_error);
        return $html;
    }, true);
});
add_action('wpcf7_init', function () {
    wpcf7_add_shortcode('submit', function ($tag) {
        $tag = new WPCF7_Shortcode($tag);
 /**
  * Outputs the HTML for the textarea shortcode.  We're replacing the default
  * CF7 textarea shortcode.  If the user wants a word limit instead of a character
  * limit, we need to remove the maxlength attribute from the element.
  *
  * @param $tag
  * @return string
  */
 function textarea_shortcode_handler($tag)
 {
     $tag = new WPCF7_Shortcode($tag);
     if (empty($tag->name)) {
         return '';
     }
     $validation_error = wpcf7_get_validation_error($tag->name);
     $class = wpcf7_form_controls_class($tag->type);
     if ($validation_error) {
         $class .= ' wpcf7-not-valid';
     }
     $atts = array();
     $atts['cols'] = $tag->get_cols_option('40');
     $atts['rows'] = $tag->get_rows_option('10');
     $atts['maxlength'] = $tag->get_maxlength_option();
     $atts['minlength'] = $tag->get_minlength_option();
     if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
         unset($atts['maxlength'], $atts['minlength']);
     }
     $maxlengthwords = false;
     $minlengthwords = false;
     // Check whether the field has a min or max word length
     foreach ($tag->options as $key => $option) {
         if (stristr($option, 'maxlengthwords:true')) {
             $maxlengthwords = true;
         }
         if (stristr($option, 'minlengthwords:true')) {
             $minlengthwords = true;
         }
     }
     // If this field has either the min or max word length validation,
     // remove the maxlength and minlength variables because we aren't
     // validating for character length
     if ($maxlengthwords === true || $minlengthwords === true) {
         unset($atts['maxlength'], $atts['minlength']);
     }
     $atts['class'] = $tag->get_class_option($class);
     $atts['id'] = $tag->get_id_option();
     $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
     if ($tag->has_option('readonly')) {
         $atts['readonly'] = 'readonly';
     }
     if ($tag->is_required()) {
         $atts['aria-required'] = 'true';
     }
     $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
     $value = empty($tag->content) ? (string) reset($tag->values) : $tag->content;
     if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
         $atts['placeholder'] = $value;
         $value = '';
     }
     $value = $tag->get_default_option($value);
     $value = wpcf7_get_hangover($tag->name, $value);
     $atts['name'] = $tag->name;
     $atts = wpcf7_format_atts($atts);
     $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', sanitize_html_class($tag->name), $atts, esc_textarea($value), $validation_error);
     return $html;
 }
예제 #12
0
function mango_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $html = '';
    $count = 0;
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    $defaults = array_unique($defaults);
    $hangover = wpcf7_get_hangover($tag->name, $multiple ? array() : '');
    $i = 0;
    foreach ($values as $key => $value) {
        if ($value == 'mango_same_line' || $value == 'mango_custom') {
            continue;
        }
        $ex = explode("|", $tag->raw_values[$i]);
        $i++;
        if (count($ex) == 1) {
            $disable = '';
        } else {
            $disable = $ex[1];
        }
        $class = 'wpcf7-list-item';
        $checked = false;
        if ($hangover) {
            if ($multiple) {
                $checked = in_array(esc_sql($value), (array) $hangover);
            } else {
                $checked = $hangover == esc_sql($value);
            }
        } else {
            $checked = in_array($key + 1, (array) $defaults);
        }
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            if (in_array('mango_custom', $values)) {
                $item = sprintf('<span>%1$s</span><span class="custom-' . esc_attr($tag->basetype) . '-container"><input %2$s  /><span class="custom-' . esc_attr($tag->basetype) . '-icon"></span></span>', esc_html($label), $item_atts);
            } else {
                $item = sprintf('%1$s&nbsp;<input %2$s %3$s />', esc_html($label), $item_atts, $disable);
            }
        } else {
            if (in_array('mango_custom', $values)) {
                $item = sprintf('<span class="custom-' . esc_attr($tag->basetype) . '-container"><input %2$s  /><span class="custom-' . esc_attr($tag->basetype) . '-icon"></span></span><span>%1$s</span>', esc_html($label), $item_atts);
            } else {
                $item = sprintf('<input %2$s %3$s />&nbsp;%1$s', esc_html($label), $item_atts, $disable);
            }
        }
        if ($use_label_element) {
            if (in_array('mango_same_line', $values)) {
                if (in_array('mango_custom', $values)) {
                    if (!empty($disable)) {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline custom-' . esc_attr($tag->basetype) . '-wrapper disabled">' . $item . '</label>';
                    } else {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline custom-' . esc_attr($tag->basetype) . '-wrapper">' . $item . '</label>';
                    }
                } else {
                    if (!empty($disable)) {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline disabled">' . $item . '</label>';
                    } else {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline">' . $item . '</label>';
                    }
                }
            } else {
                if (in_array('mango_custom', $values)) {
                    if (!empty($disable)) {
                        $item = '<div class="' . esc_attr($tag->basetype) . ' disabled"><label class="custom-' . esc_attr($tag->basetype) . '-wrapper">' . $item . '</label></div>';
                    } else {
                        $item = '<div class="' . esc_attr($tag->basetype) . '"><label class="custom-' . esc_attr($tag->basetype) . '-wrapper">' . $item . '</label></div>';
                    }
                } else {
                    if (!empty($disable)) {
                        $item = '<div class="' . esc_attr($tag->basetype) . ' disabled"><label>' . $item . '</label></div>';
                    } else {
                        $item = '<div class="' . esc_attr($tag->basetype) . '"><label>' . $item . '</label></div>';
                    }
                }
            }
        }
        if (false !== $tabindex) {
            $tabindex += 1;
        }
        $count += 1;
        if (1 == $count) {
            $class .= ' first';
        }
        if (count($values) == $count) {
            $class .= ' last';
            if ($free_text) {
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text_atts = array('name' => $free_text_name, 'class' => 'wpcf7-free-text', 'tabindex' => $tabindex ? $tabindex : '');
                if (wpcf7_is_posted() && isset($_POST[$free_text_name])) {
                    $free_text_atts['value'] = wp_unslash($_POST[$free_text_name]);
                }
                $free_text_atts = wpcf7_format_atts($free_text_atts);
                $item .= sprintf(' <input type="text" %s />', $free_text_atts);
                $class .= ' has-free-text';
            }
        }
        $disable = '';
        $html .= $item;
    }
    $atts = wpcf7_format_atts($atts);
    if (empty($values)) {
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => 'yes');
        $item_atts = wpcf7_format_atts($item_atts);
        $html = sprintf('<span class="input-group-addon no-minwidth custom-' . esc_attr($tag->basetype) . '-wrapper">
			<span class="custom-' . esc_attr($tag->basetype) . '-container">
			<input %1$s>
			<span class="custom-' . esc_attr($tag->basetype) . '-icon"></span>
			</span>
			</span>', $item_atts);
        $html = sprintf('%1$s%2$s', $html, $validation_error);
    } else {
        $html = sprintf('<div %1$s>%2$s&nbsp;%3$s</div>', $atts, $html, $validation_error);
    }
    return $html;
}