如何联系表格7个WordPress的模式添加到输入

问题描述 投票:-1回答:1

我有这样的代码联系表7:文本* name占位符“姓名*”]我想这个输入只接受卡拉科特任何帮助,请!

wordpress contact-form-7
1个回答
0
投票

使用自定义代码:

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

function alphanumeric_validation_filter( $result, $tag ) {
$tag = new WPCF7_Shortcode( $tag );

if ( 'name' == $tag->name ) {
$name_of_the_input = isset( $_POST['name'] ) ? trim( $_POST['name'] ) : '';

if ( !preg_match('/^[a-zA-Z]+$/',$name_of_the_input) ) {
$result->invalidate( $tag, "Allowed characters only" );
}
}

return $result;
}

验证使用插件:

https://wordpress.org/plugins/jquery-validation-for-contact-form-7/

© www.soinside.com 2019 - 2024. All rights reserved.