admin管理员组文章数量:1122832
Could someone help me to solve the problem. I would like the system work like bellow.
- If both fields are empty = invalid.
- If any of the fields is completed = valid
add_filter('wpcf7_validate_text', 'or_input_validation_filter', 20, 2);
function or_input_validation_filter($result, $tag) {
if ('your-link' == $tag->name) {
$your_link = isset($_POST['your-link']) ? trim($_POST['your-link']) : '';
$your_file = isset($_FILES['your-file']) ? trim($_FILES['your-file']['name']) : '';
if($your_link == '' && $your_file == '') {
$result->invalidate($tag, "One of the fields has not been completed?");
}
}
return $result;
}
Could someone help me to solve the problem. I would like the system work like bellow.
- If both fields are empty = invalid.
- If any of the fields is completed = valid
add_filter('wpcf7_validate_text', 'or_input_validation_filter', 20, 2);
function or_input_validation_filter($result, $tag) {
if ('your-link' == $tag->name) {
$your_link = isset($_POST['your-link']) ? trim($_POST['your-link']) : '';
$your_file = isset($_FILES['your-file']) ? trim($_FILES['your-file']['name']) : '';
if($your_link == '' && $your_file == '') {
$result->invalidate($tag, "One of the fields has not been completed?");
}
}
return $result;
}
Share
Improve this question
asked May 24, 2022 at 18:25
RobertRobert
112 bronze badges
1 Answer
Reset to default 1I solved my problem
add_filter('wpcf7_validate_text', 'or_input_validation_filter', 20, 2);
function or_input_validation_filter($result, $tag) {
if ('your-link' == $tag->name) {
$your_link = isset($_POST['your-link']) ? trim($_POST['your-link']) : '';
$your_file = (!empty($_FILES["file-image"]["name"])) ? trim($_FILES['file-image']['name']) : '';
if($your_link == '' && $your_file == '') {
$result->invalidate($tag, "One of the fields has not been completed?");
}
}
return $result;
}
本文标签: phpContact Form 7 Wordpresschecking a few fieldsif empty then invalid
版权声明:本文标题:php - Contact Form 7 Wordpress, checking a few fields, if empty then invalid 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307937a1933485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论