我在CF-7表单上添加了一些额外字段,除了响应消息框外,一切正常。我得到这样的东西
https://i.stack.imgur.com/JulGC.png
但我希望只在我的“提交”按钮旁边显示错误消息。
无论如何我可以存档吗?我是wordpress的新手,所以我不确定我从哪里开始。
答案 0 :(得分:0)
您可以使用jquery验证。您可以通过联系表单7轻松实现jquery验证
这是jquery验证的示例代码。
$(".wpcf7-form").validate({
rules: {
yourname: "required",
youremail: {
required: true,
email: true
},
},
messages: {
yourname: "Please include your name.",
youremail: "Please include a valid email address.",
yourmessage: "Please tell me how I can help you.",
},
});
或PHP代码,Link contact form 7
add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );
function custom_email_confirmation_validation_filter( $result, $tag ) {
if ( 'your-email-confirm' == $tag->name ) {
$your_email = isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
$your_email_confirm = isset( $_POST['your-email-confirm'] ) ? trim( $_POST['your-email-confirm'] ) : '';
if ( $your_email != $your_email_confirm ) {
$result->invalidate( $tag, "Are you sure this is the correct address?" );
}
}
return $result;
}
或者可以使用此插件。 Jquery Validation For Contact Form 7
希望这个wiull可以帮助你。