I need to use PHP on my WordPress site to restrict who can submit a specific form. I only want to allow those using a specific email domain to be able to submit a form. Below is the code I am using. The code works. The issue is I have 400+ domains that I need to whitelist. I am hoping to use an array but I don't know if this is the best way. Bottom line is I am hoping someone can help adjust the code below to show me how to add additional domains. In the code below, the only domain currently whitelisted is example.com.
add_filter('frm_validate_field_entry', 'check_valid_email', 10, 3);
function check_valid_email($errors, $posted_field, $posted_value){
if($posted_field->id == 7){
$postedemail=$_POST['item_meta'][7];
$alloweddomain = explode('@',$postedemail)[1];
if (!filter_var($postedemail, FILTER_VALIDATE_EMAIL) || $alloweddomain != 'example.com') {
$errors['field'. $posted_field->id] = 'Sorry! You are not allowed to submit this form';
}
}
return $errors;
}