【发布时间】:2014-02-24 05:28:51
【问题描述】:
我正在尝试找到一种解决方案,仅使用 Ninja Forms 插件在 Wordpress 中验证带有 .edu 扩展名的电子邮件。
使用联系表 7,我可以这样做:
function is_edu($email) {
if(substr($email, -4) == '.edu') {
return true;
} else {
return false;
};
};
function custom_email_validation_filter($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
if($name == 'your-email') { // Only apply to fields with the form field name of "your-email"
$the_value = $_POST[$name];
if(!is_edu($the_value)){
$result['valid'] = false;
$result['reason'][$name] = 'This is not a .edu address!'; // Error message
};
};
return $result;
};
add_filter('wpcf7_validate_email','custom_email_validation_filter', 10, 2); // Email field
add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 10, 2); // Required Email field
【问题讨论】:
标签: php wordpress forms email-validation