I am trying to:
add_filter('cred_form_validate','func_validate_listing',10,2);
function func_validate_listing ($error_fields, $form_data){
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific for
if ($form_data['id']==1126){
$args = array(
'meta_query' => array(
'relation' => 'AND',
array('key' => 'wpcf-field1',
'value' => $_POST['wpcf-field1']),
array('key' => 'wpcf-field2',
'value' => $_POST['wpcf-field2']),
array('key' => 'wpcf-field3',
'value' => $_POST['wpcf-field3']),
array('key' => 'wpcf-field4',
'value' => $_POST['wpcf-field4']),
array('key' => 'wpcf-field5t',
'value' => $_POST['wpcf-field5']),
),
'post_type' => 'upn',
'posts_per_page' => -1
);
$posts = get_posts($args);
//check if this unit is already on the database
if (count($posts) > 0){
//set error message for my_field
$errors['wpcf-field5']='This unit is already listed';
}
}
//return result
return array($fields,$errors);
}
Link to a page where the issue can be seen:
I expected to see: AN error message. I also use the JS code that I found on anoyther example but I don't see anything.
Need to know how I can generate an error so that no 2 person can submit the same property listing.