以联系表格7文本添加模式

时间:2018-05-30 12:58:56

标签: wordpress contact-form-7

我有一个与Pattern =" [A-Za-z]"相关的查询。在联系表格7中以文字*你的名字设置

当此表单有效时,即使客户端也会以联系方式发送号码(假名)。我想阻止它,让他们只按字母顺序输入名称。

提前感谢您提出建议和意见。

我目前的文字标签代码如下。

<label> Your Name (Required)
<p>[text* your-name placeholder "Name"] </p></label>

2 个答案:

答案 0 :(得分:1)

假设您的联系表单字段为此,其中包含id&#39; firstname&#39;

if(isset($_POST["selectedProject"])){
    $proy = $_POST["selectedProject"];
    $output = "<option value='100'> Select your category </option>";
    if($proy != 0){
        $output.= "<option>" . $proy . "</option>"; 
    }
    echo $output;
    exit; // <-- halt so none of the other following html spills out
}

然后将此脚本放在footer.php或header.php文件中,只需更改字段的id。

喜欢

[text text-703 id:firstname placeholder "first name"]   

答案 1 :(得分:0)

您可以使用自定义过滤器进行验证

add_filter( 'wpcf7_validate_text*', 'custom_text_validation_filter', 20, 2 );

function custom_text_validation_filter( $result, $tag ) {
    if ( 'your-name' == $tag->name ) {
        // matches any utf words with the first not starting with a number
        $re = '/^[^\p{N}][\p{L}]*/i';

        if (!preg_match($re, $_POST['your-name'], $matches)) {
            $result->invalidate($tag, "This is not a valid name!" );
        }
    }

    return $result;
}
相关问题