Home › Forums › Front-end Issues › Don't update email if it exists. Show error on same page in › Reply To: Don't update email if it exists. Show error on same page in
Here is what I came up with:
add_filter('acf/validate_value/name=my_user_email', 'my_acf_validate_value', 10, 4);
function my_acf_validate_value( $valid, $value, $field, $input ){
if($value == "" || $value == " ") {
$valid = "Email field cannot be empty";
} elseif( email_exists($value) ) {
$valid = "This email already exists. Use a unique email";
}
return $valid;
}
If a users email is [email protected] and they try another email that already exists or nothing then they get the respective errors. So far so good. If they try to change their email back to [email protected] they can’t because of the email_exists($value). Even though that is the what we want because they’re actual email is [email protected]. That was never changed. Can we do a check as follows
If email exists then show error “This email exists already” unless the user’s actual email (wordpress user email) is the ACF field value being entered. Then that is OK and that is the exception.
I can see users trying to change their email to something else. seeing the error. then saying “I’m going to change it back to my old email”. and if they do it exists because the WordPress email was never changed.
So close
If user
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.