• Resolved Raghav

    (@mraghavboob)


    Hii Sir,

    I want to generate sequential numbers in forminator form but I was unable to create. I am using below code but not working for me.

    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++;
    				}
    				echo "<script>console.log('Debug Objects: " . $incremental . "' );</script>";
    
    				$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
    );
    

    Please review the code and help me.

    Thanks and Regards,

    Raghav

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @raghav,

    Please try this snippet and then check whether it helps:

    <?php
    
    add_action(
    	'forminator_custom_form_submit_before_set_fields',
    	function( $entry, $form_id, $field_data_array ){
    	// 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++;
    			}
    
    			Forminator_CForm_Front_Action::$info['field_data_array'][$key][ 'value' ] = $incremental;
    			$update_meta = true;
    		}
    	}
    
    	if ( $update_meta ) {
    		update_post_meta( $form_id, 'autoincrement_int', $incremental );
    	}
    },
    20, 
    3
    );

    Please do let us know how that goes.

    Best Regards,

    Nithin

    Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi?@raghav,

    We haven’t heard from you in a while, we will go ahead and mark this thread as resolved. If you have any additional questions or require further help, please let us know!

    Kind regards,
    Zafer

    Thread Starter Raghav

    (@mraghavboob)

    Apologies, Forgot to reply.

    Code Worked.

    Thank you so much ..

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sequential Numbers in form’ is closed to new replies.