Home › Forums › Add-ons › Repeater Field › Validation for Date Range › Reply To: Validation for Date Range
There’s a semicolon missing near the end. There’s no syntax checker here and I just type code straight into the message most of the time assuming that people can correct minor syntax errors when needed.
add_filter('acf/validate_value/name=end_date', 'validate_end_date_func', 10, 4);
function validate_end_date_func($valid, $value, $field, $input) {
if (!$valid) {
return $valid;
}
$repeater_key = 'field_56faad2a333ab';
$start_key = 'field_56fab49fd51ce';
$end_key = 'field_56fab4d1d51d0';
// extract row from input
$row = preg_replace('/^\s*acf\[[^\]]+\]\[([^\]]+)\].*$/', '\1', $input);
$start_value = $_POST['acf'][$repeater_key][$row][$start_key];
$end_value = $value;
if ($end_value <= $start_value) {
$valid = 'end value must be greater than start value';
}
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!
🚨 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.