Home › Forums › General Issues › Dont save post if sum of all repeater-fields are more than 100? › Reply To: Dont save post if sum of all repeater-fields are more than 100?
You need to and an acf/validate_value filter to the sub field, use the field key variant.
// field_XXXXXXX == your sub field key
add_filter('acf/validate_value/key=field_XXXXXXX', 'validate_repeater_sum', 20, 4);
function validate_repeater_sum($valid, $value, $field, $input_name) {
// field_YYYYYYY == your repeater field key
$repeater = $_POST['acf']['field_YYYYYYY'];
$sum = 0;
foreach ($repeater as $row) {
$sum += intval($row['field_XXXXXXX']);
}
if ($sum > 100) {
$valid = 'The sum of all '.$field['label'].' fields must not exceed 100';
}
return $valid;
}
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.