Support

Account

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.