Setting repeater field number maximum

By: Philip Clayton | Asked: 07/11/2022
ForumsCategory: How-toSetting repeater field number maximum
Philip ClaytonPhilip Clayton asked 2 years ago

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.
 
 

 

 

 

 

 

 

 

Attachments
1 Answers
Best Answer
Bobby Clapp answered 2 years ago
Try this. This is a manipulation of the code found here -> https://formidableforms.com/knowledgebase/frm_validate_field_entry/#kb-check-for-duplicates-in-repeating-fields 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; }
Philip ClaytonPhilip Clayton replied 2 years ago

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.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right