Home › Forums › General Issues › Validate Front End Form Submission – Unique Values only › Reply To: Validate Front End Form Submission – Unique Values only
// your should only be testing the vacancy field
// insert the field key of your field here
add_filter('acf/validate_value/key=field_YYYYYYY', 'acf_duplicate_candidate_application', 10, 4);
function acf_duplicate_candidate_application($valid, $value, $field, $input) {
// acf now uses $_POST['_acf_post_id']
// the other $_POST indexes may not be available on the front end
if (!$valid || !isset($_POST['_acf_post_id'])) {
return $valid;
}
$post_id = intval($_POST['_acf_post_id']);
$post_type = get_post_type($post_id);
// to get pother values submitted you must look in $_POST['acf'][$field_key]
$candidate_email = $_POST['acf']['field_XXXXXXX']; // field key of email field
$args = array(
'post_type' => $post_type,
'post_status' => 'publish, draft, trash', // double check possible post statuses
'post__not_in' => array($post_id),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'candidate_email', // field name
'value' => $candidate_email
),
array(
'key' => 'vacancy_applied_for', // field name
'value' => $value
)
)
);
$query = new WP_Query($args);
if (count($query->posts)){
return 'You have already applied for this vacancy.';
}
return true;
}
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.