possible to reset ato increment when change in another field value?

By: andy Morris | Asked: 04/10/2024
ForumsCategory: General questionspossible to reset ato increment when change in another field value?
andy Morris asked 8 months ago

I want to create an entry counter that resets each time a value in a lookup field changes. similar to this example below but not based on User ID.

Use case: user creates a production name in Form A. in form B they must select a production from form A using a look up drop down. I want to create an incremental entry ID that resets each time a new production name is selected. Form B will have multiple entries for each production. End result:

Job1.1, Job1.2 Job1.2 then change production name to Job2 and start a new sequence Job2.1, Job2.2 job3.3 etc.

There is a very close example in FF dev tools below but the change/reset is based on User ID rather than some other value.

Entry counter for each user#

Use this code to have a field in your form that has a counter for each user. It works similarly to the [auto_id] shortcode, but each user has their own count, starting with 1 and increasing for each entry they submit.

Change 2806 to the counter field in your form.

add_filter('frm_validate_field_entry', 'add_user_entry_counter', 10, 3);

function add_user_entry_counter($errors, $posted_field, $posted_value){
	$field_id = 2806; // Change 2806 to the ID of the user entry counter field.
	if ( $posted_field->id == $field_id ) {
		$previous_value = FrmProEntriesController::get_field_value_shortcode( array( 'field_id' => $field_id, 'user_id' => 'current' ) );
		$_POST['item_meta'][$posted_field->id] = $previous_value ? (int)$previous_value + 1 : 1;
	}
	return $errors;
}

 

 

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