Hello, how have others managed to "total up" the values of a number field in a repeater and stop the number field from exceeding this?
Eg, in this use case, a limit of 8 is to be set regardless of how many repeater rows with this number field there are. The screenshot attached explains exactly what's needed. All 3 quantity fields must not total more than 8.
Currently, the one repeater row is set 1-8 min/max.
Kind regards and thanks for anybody's time replying
Edit: updated screenshot to be as clear as possible.
add_filter( 'frm_validate_field_entry', 'check_repeating_value_for_duplicates', 10, 4 );
function check_repeating_value_for_duplicates( $errors, $posted_field, $posted_value, $args ){
if ( $posted_field->id == 12692 ) { //Replace 12692 with the ID of the repeater field.
$field_to_check = 12694; //Replace 12694 with the ID of the field inside the repeater.
$vals = array();
if ( ! isset( $_POST['item_meta'][ $posted_field->id ] ) ) {
return $errors;
}
foreach ( $_POST['item_meta'][ $posted_field->id ] as $row_num => $section_vals ) {
if ( $row_num === 'form' ) {
continue;
}
array_push( $vals, $_POST['item_meta'][ $posted_field->id ][ $row_num ][ $field_to_check ] );
}
if( array_sum($vals) > 8 ){
$errors[ $field_to_check ] = 'The total of quantities must be 8 or less.';
}
}
return $errors;
}
Hi Bobby, thanks for this, it does indeed refuse to submit a form with a total of more than 8. Thank you for your time, I'll send this to formidable to put in their documentation so it's also easily findable.
Please login or Register to submit your answer