我在联系表格7中有以下代码: [文本*名称占位符“名称*”] 我希望此输入仅接受角色 请帮忙!
答案 0 :(得分: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/