コード例 #1
0
function wpcf7_text_custom_validation_message($result, $tag)
{
    $cmtagobj = new WPCF7_Shortcode($tag);
    $post_id = sanitize_text_field($_POST['_wpcf7']);
    $name = $cmtagobj->name;
    $key = "_cf7cm_" . $name;
    $val = get_post_meta($post_id, $key, true);
    $enable = get_post_meta($post_id, '_cf7cm_enable_errors');
    if ($enable[0] != 0) {
        $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
        if ('text' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            }
        }
        if ('email' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            } elseif ('' != $value && !wpcf7_is_email($value)) {
                $key = "_cf7cm_" . $name . "-valid";
                $val = get_post_meta($post_id, $key, true);
                if ($val) {
                    $result->invalidate($cmtagobj, $val);
                } else {
                    $result->invalidate($cmtagobj, wpcf7_get_message('invalid_email'));
                }
            }
        }
        if ('url' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            } elseif ('' != $value && !wpcf7_is_url($value)) {
                $result->invalidate($cmtagobj, wpcf7_get_message('invalid_url'));
            }
        }
        if ('tel' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            } elseif ('' != $value && !wpcf7_is_tel($value)) {
                $result->invalidate($cmtagobj, wpcf7_get_message('invalid_tel'));
            }
        }
        if (!empty($value)) {
            $maxlength = $cmtagobj->get_maxlength_option();
            $minlength = $cmtagobj->get_minlength_option();
            if ($maxlength && $minlength && $maxlength < $minlength) {
                $maxlength = $minlength = null;
            }
            $code_units = wpcf7_count_code_units($value);
            if (false !== $code_units) {
                if ($maxlength && $maxlength < $code_units) {
                    $result->invalidate($cmtagobj, wpcf7_get_message('invalid_too_long'));
                } elseif ($minlength && $code_units < $minlength) {
                    $result->invalidate($cmtagobj, wpcf7_get_message('invalid_too_short'));
                }
            }
        }
    }
    return $result;
}
コード例 #2
0
ファイル: text.php プロジェクト: aim-web-projects/kobe-chuoh
function wpcf7_text_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('text*' == $tag->type) {
        if ('' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    if ('email' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_email($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_email');
        }
    }
    if ('url' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_url($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_url');
        }
    }
    if ('tel' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_tel($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_tel');
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
function wpcf7_confirm_email_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->basetype;
    $name = $tag->name;
    $values = $tag->values;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('confirm_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'));
        } elseif ($value != $_POST['your-email']) {
            $result->invalidate($tag, wpcf7_get_message('invalid_confirm_email'));
        }
    }
    return $result;
}
コード例 #4
0
ファイル: text.php プロジェクト: flasomm/Montkailash
function wpcf7_text_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($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($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;
}
コード例 #5
0
ファイル: formatting.php プロジェクト: xeiter/timeplannr
function wpcf7_is_mailbox_list($mailbox_list)
{
    if (!is_array($mailbox_list)) {
        $mailbox_list = explode(',', (string) $mailbox_list);
    }
    $addresses = array();
    foreach ($mailbox_list as $mailbox) {
        if (!is_string($mailbox)) {
            return false;
        }
        $mailbox = trim($mailbox);
        if (preg_match('/<(.+)>$/', $mailbox, $matches)) {
            $addr_spec = $matches[1];
        } else {
            $addr_spec = $mailbox;
        }
        if (!wpcf7_is_email($addr_spec)) {
            return false;
        }
        $addresses[] = $addr_spec;
    }
    return $addresses;
}
コード例 #6
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->form_scan_shortcode(array('name' => $tagname));
     if ($form_tags) {
         $form_tag = new WPCF7_Shortcode($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_email($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;
 }