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.
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;
}
Please login or Register to submit your answer