• Resolved greenrooster

    (@greenrooster)


    Hi, is there a way to implement sequential numbering per form submission? We have a maintenance order form that either a) needs to have sequential numbering that is not affected by submissions from other forms or b) have a timestamp for the submission. At the moment, submission numbering is based on all submissions in the database, and the best that can be done for a timestamp is the mm/dd/yyy date.

    I figure there is not a way in the base plugin, but are there any hooks/code I can use to achieve either solution?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @greenrooster,

    Thank you for contacting us.

    The feature you are describing is currently not available. The good news is this has been added as a feature request already, so our Plugin team is looking into to consider it for a future release. As a possible workaround, you may try the following snippet as an MU plugin or in theme’s function, which uses a hidden field that will allow to add an incremental ID for each submission:

    add_filter( 
    	'forminator_custom_form_submit_field_data',
    	function( $field_data_array, $form_id ){
    
    		// We're using a custom macro <code>AUTOINCREMENT_INT</code> set as value for a field.
    		// Make sure you add this value only in hidden fields
    		$needle      = 'AUTOINCREMENT_INT';
    		$incremental = get_post_meta( $form_id, 'autoincrement_int', true );
    		$update_meta = false;
    
    		foreach ( $field_data_array as $key => $field_data ) {
    			if ( isset( $field_data[ 'value' ] ) && $needle === $field_data[ 'value' ] ) {
    
    				if ( ! $incremental ) {
    					$incremental = 1;
    				} else {
    					$incremental++;
    				}
    
    				$field_data_array[$key][ 'value' ] = $incremental;
    				$update_meta                       = true;
    			}
    		}
    
    		if ( $update_meta ) {
    			update_post_meta( $form_id, 'autoincrement_int', $incremental );
    		}
    
    		return $field_data_array;
    	},
    	20, 
    	2
    );

    In order to make this work, add a hidden field to the form and make the hidden field’s Default Value to Custom and add this macro as value AUTOINCREMENT_INT.

    That should create a new post meta that will hold that value. Initially (it will be empty) and then it will set it to 1(you can change the 1 in Snippet to a different starting value). Then on each submit it should increment by one.

    Best,
    Jonathan S

    This snippet works… But when I use the hidden field slug {hidden-1} in ie email subject or email body – all I get is “AUTOINCREMENT_INT”. The only way to output the right value is using {all_fields} – which is unhandy.

    So an incremental field type would be great to have – if it plays nicely in other places like email notifications or calculations etc…

    Thread Starter greenrooster

    (@greenrooster)

    Thanks, @wpmudev-support9, I’ll try this out when I am able.

    @filak18, I agree, long term this would be great to have and utilize in areas like the email body and subject. For now, this will be a fine solution for me.

    Thread Starter greenrooster

    (@greenrooster)

    @wpmudev-support9 This works exactly like I need it to. Thank you! I’m closing this ticket now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sequential Numbering Form Submission’ is closed to new replies.