Esempio n. 1
0
function wpcf7_textarea_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    if (!empty($value)) {
        $maxlength = $tag->get_maxlength_option();
        $minlength = $tag->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
        $code_units = wpcf7_count_code_units(stripslashes($value));
        if (false !== $code_units) {
            if ($maxlength && $maxlength < $code_units) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
            } elseif ($minlength && $code_units < $minlength) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
            }
        }
    }
    return $result;
}
Esempio n. 2
0
function wpcf7_file_form_tag_handler($tag)
{
    $tag = new WPCF7_FormTag($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['size'] = $tag->get_size_option('40');
    $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';
    $atts['type'] = 'file';
    $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;
}
Esempio n. 3
0
function wpcf7_text_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('text' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        }
    }
    if ('email' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_email($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_email'));
        }
    }
    if ('url' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_url($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_url'));
        }
    }
    if ('tel' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_tel($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_tel'));
        }
    }
    if (!empty($value)) {
        $maxlength = $tag->get_maxlength_option();
        $minlength = $tag->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
        $code_units = wpcf7_count_code_units(stripslashes($value));
        if (false !== $code_units) {
            if ($maxlength && $maxlength < $code_units) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
            } elseif ($minlength && $code_units < $minlength) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
            }
        }
    }
    return $result;
}
Esempio n. 4
0
function wpcf7_date_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    $min = $tag->get_date_option('min');
    $max = $tag->get_date_option('max');
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    } elseif ('' != $value && !wpcf7_is_date($value)) {
        $result->invalidate($tag, wpcf7_get_message('invalid_date'));
    } elseif ('' != $value && !empty($min) && $value < $min) {
        $result->invalidate($tag, wpcf7_get_message('date_too_early'));
    } elseif ('' != $value && !empty($max) && $max < $value) {
        $result->invalidate($tag, wpcf7_get_message('date_too_late'));
    }
    return $result;
}
Esempio n. 5
0
function wpcf7_number_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    $min = $tag->get_option('min', 'signed_int', true);
    $max = $tag->get_option('max', 'signed_int', true);
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    } elseif ('' != $value && !wpcf7_is_number($value)) {
        $result->invalidate($tag, wpcf7_get_message('invalid_number'));
    } elseif ('' != $value && '' != $min && (double) $value < (double) $min) {
        $result->invalidate($tag, wpcf7_get_message('number_too_small'));
    } elseif ('' != $value && '' != $max && (double) $max < (double) $value) {
        $result->invalidate($tag, wpcf7_get_message('number_too_large'));
    }
    return $result;
}
Esempio n. 6
0
function wpcf7_select_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    if (isset($_POST[$name]) && is_array($_POST[$name])) {
        foreach ($_POST[$name] as $key => $value) {
            if ('' === $value) {
                unset($_POST[$name][$key]);
            }
        }
    }
    $empty = !isset($_POST[$name]) || empty($_POST[$name]) && '0' !== $_POST[$name];
    if ($tag->is_required() && $empty) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    return $result;
}
Esempio n. 7
0
function wpcf7_checkbox_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (array) $_POST[$name] : array();
    if ($tag->is_required() && empty($value)) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    return $result;
}
Esempio n. 8
0
 public function replace_mail_tags_with_minimum_input($matches)
 {
     // allow [[foo]] syntax for escaping a tag
     if ($matches[1] == '[' && $matches[4] == ']') {
         return substr($matches[0], 1, -1);
     }
     $tag = $matches[0];
     $tagname = $matches[2];
     $values = $matches[3];
     if (!empty($values)) {
         preg_match_all('/"[^"]*"|\'[^\']*\'/', $values, $matches);
         $values = wpcf7_strip_quote_deep($matches[0]);
     }
     $do_not_heat = false;
     if (preg_match('/^_raw_(.+)$/', $tagname, $matches)) {
         $tagname = trim($matches[1]);
         $do_not_heat = true;
     }
     $format = '';
     if (preg_match('/^_format_(.+)$/', $tagname, $matches)) {
         $tagname = trim($matches[1]);
         $format = $values[0];
     }
     $example_email = '*****@*****.**';
     $example_text = 'example';
     $example_blank = '';
     $form_tags = $this->contact_form->scan_form_tags(array('name' => $tagname));
     if ($form_tags) {
         $form_tag = new WPCF7_FormTag($form_tags[0]);
         $is_required = $form_tag->is_required() || 'radio' == $form_tag->type;
         if (!$is_required) {
             return $example_blank;
         }
         $is_selectable = in_array($form_tag->basetype, array('radio', 'checkbox', 'select'));
         if ($is_selectable) {
             if ($form_tag->pipes instanceof WPCF7_Pipes) {
                 if ($do_not_heat) {
                     $before_pipes = $form_tag->pipes->collect_befores();
                     $last_item = array_pop($before_pipes);
                 } else {
                     $after_pipes = $form_tag->pipes->collect_afters();
                     $last_item = array_pop($after_pipes);
                 }
             } else {
                 $last_item = array_pop($form_tag->values);
             }
             if ($last_item && wpcf7_is_mailbox_list($last_item)) {
                 return $example_email;
             } else {
                 return $example_text;
             }
         }
         if ('email' == $form_tag->basetype) {
             return $example_email;
         } else {
             return $example_text;
         }
     } else {
         $tagname = preg_replace('/^wpcf7\\./', '_', $tagname);
         // for back-compat
         if ('_post_author_email' == $tagname) {
             return $example_email;
         } elseif ('_' == substr($tagname, 0, 1)) {
             // maybe special mail tag
             return $example_text;
         }
     }
     return $tag;
 }