Home › Forums › Backend Issues (wp-admin) › Validate_value fails with get_field_object is used › Reply To: Validate_value fails with get_field_object is used
I have figured out what’s wrong:
$startDateObj = get_field_object('start_date', false, false, false) ?? null;
$key = $startDateObj['key'] ?? null;
$startDate = $_POST['acf'][$key] ?? null;
if(empty($startDate)) {
return $valid;
}
On the ajax call, it will be return as valid because get_field_object() returns false, therefor $key
and $startDate
will both have value null
(not undefined index) and in the end empty($startDate)
will be true. Which means it will pass the Ajax validation but, will fail when it runs the PHP validation because get_field_object()
will not return false.
Is there a way to fetch fields structure without relying on existing post? To have a list of static keys is not a good solution is in this case and I woludn’t want to add a custom javascript validation on top of AFC.
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.