• Resolved ejaganece

    (@ejaganece)


    Hi, i have some doubts with creating post creation. I plan to create one Post Type with Custom fields for different form(Answer Sheet Copy, Marksheet Verification, Passport Delay, Income Tax Refund, FIR Status). And have one custom field with status (Pending, Processing, Completed).

    1. Is it possible to set form title as category in CPT.
    2. Need to create Unique ID for each form submit with different form.
    3. I plan to display the status (Pending, Processing, Completed) in front end with based on Unique ID. Can you please confirm this one is possible or not.

    Thanks,
    Jagan

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @ejaganece

    I hope you are doing well today.

    I pinged our SLS Team to review your query and see what will be possible in this case. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Hi @ejaganece,

    Hope this message finds you well and sorry for our delayed response.

    Our Second Line Support team provided this workaround:

    1. Assigning form title as the category:

    add_action(
    'forminator_post_data_field_post_saved',
    	function( $post_id, $field, $data ) {
            $form_data = Forminator_CForm_Front_Action::$prepared_data;
            $form_title = get_the_title( $form_data['form_id'] );
    		wp_set_object_terms( $post_id, $form_title, 'category' );
    },10,3);

    2. Every submission for each form is unique already.

    3. I plan to display the status (Pending, Processing, Completed) in front end with based on Unique ID. Can you please confirm this one is possible or not.

    For each post you can access the meta value by using get_post_meta method. Example:

    add_filter( 'the_content', 'wpmudev_add_post_status', 9999 );
    function wpmudev_add_post_status( $content ) {
        $status = get_post_meta( get_the_ID(), 'status', true );
        $content = $status . '<br/>' . $content;
        return $content;
    }

    You might need to install it as a mu-plugin following the instructions on this link https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins.

    Let us know if you require additional information.

    Best regards,
    Laura

    Hi @ejaganece,

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved. Note that you can still reply on this topic.

    If you have any additional questions or require further help, please let us know!

    Best regards,
    Laura

    Thread Starter ejaganece

    (@ejaganece)

    Thanks for the reply, Can you please tell how can i set unique ID for each form submission in custom post filed.

    Thanks,
    Jagan

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ejaganece

    Each form submission already has a unique ID – no two submissions will ever have the same ID even if they come from multiple different forms.

    By design, you can add a filed of type “hidden” to the form and set it to contain “submission_id”. Then this field you can easily map to your custom post field in “post-data” field settings.

    Unfortunately, there’s a small bug currently related to that and it won’t be passed over so I asked our Second Line Support for workaround and we’ll update you here soon with more information on this.

    Best regards,
    Adam

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @ejaganece

    I just got response form our Second Line Support. To store submission ID in the post custom field, you need another piece of custom code.

    1. you don’t need to add hidden field with submission ID to the form for this and no need to map it to custom field on the form

    2. you only need to add following code to the site (similarly to the codes that you already added)

    add_action( 'plugins_loaded', 'wpmudev_assign_submission_to_new_post', 100 );
    function wpmudev_assign_submission_to_new_post() {
        if ( class_exists( 'Forminator' ) ) {
            class WPMUDEV_Dynamically_Assign_Submission_Id {
                private $new_post;
    
                public function __construct() {
                    add_action( 'forminator_post_data_field_post_saved', array( $this, 'wpmudev_post_update_handler' ) , 20, 1 );
    				add_action( 'forminator_form_after_save_entry', array( $this, 'wpmudev_update_entry_handler' ) , 20, 2 );
    				add_action( 'forminator_form_after_handle_submit', array( $this, 'wpmudev_update_entry_handler' ) , 20, 2 );
                }
    
                public function wpmudev_post_update_handler( $post_id ) {
    				$this->new_post = $post_id;
                }
    
    			public function wpmudev_update_entry_handler( $module_id, $response ) {
    				if ( $module_id != 123 ) {
    					return;
    				}
    				
    				if ( $response && is_array( $response ) ) {
    					if ( $response['success'] ) {
    						$entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $module_id );
    						update_post_meta( $this->new_post, 'CUSTOM_FIELD_NAME', $entry->entry_id );
    					}
    				}
                }
            }
    
            $run = new WPMUDEV_Dynamically_Assign_Submission_Id;
        }
    }

    3. and
    – replace number 123 in the code with your form ID
    – replace CUSTOM_FIELD_NAME in the code with the name of your custom field that you want to store submission ID in

    Best regards,
    Adam

    Thread Starter ejaganece

    (@ejaganece)

    Thanks for the reply, it’s working fine and stored ID as “10”. Is it possible to add character before number like “ORTI202410”. Currently i add one form id in that code but i have multiple forms in that case how can i add multiple form id’s.

    Thanks,
    Jagan

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @ejaganece,

    Is it possible to add character before number like “ORTI202410”. Currently i add one form id in that code but i have multiple forms in that case how can i add multiple form id’s.

    Could you please check and see whether the following suggestion helps?

    <?php
    
    add_action( 'plugins_loaded', 'wpmudev_assign_submission_to_new_post', 100 );
    function wpmudev_assign_submission_to_new_post() {
        if ( class_exists( 'Forminator' ) ) {
            class WPMUDEV_Dynamically_Assign_Submission_Id {
                private $new_post;
    
                public function __construct() {
                    add_action( 'forminator_post_data_field_post_saved', array( $this, 'wpmudev_post_update_handler' ), 20, 1 );
                    add_action( 'forminator_form_after_save_entry', array( $this, 'wpmudev_update_entry_handler' ), 20, 2 );
                    add_action( 'forminator_form_after_handle_submit', array( $this, 'wpmudev_update_entry_handler' ), 20, 2 );
                }
    
                public function wpmudev_post_update_handler( $post_id ) {
                    $this->new_post = $post_id;
                }
    
                public function wpmudev_update_entry_handler( $module_id, $response ) {
    
                    $applicable_form_ids = array(123, 456, 789); // Add your form IDs here
                    
                    // Check if the current form ID
                    if ( !in_array($module_id, $applicable_form_ids) ) {
                        return;
                    }
                    
                    if ( $response && is_array( $response ) ) {
                        if ( $response['success'] ) {
                            $entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $module_id );
                            // Add prefix before entry_id
                            $prefixed_entry_id = 'ORTI2024' . $entry->entry_id;
                            update_post_meta( $this->new_post, 'CUSTOM_FIELD_NAME', $prefixed_entry_id );
                        }
                    }
                }
            }
    
            $run = new WPMUDEV_Dynamically_Assign_Submission_Id;
        }
    }
    

    In the above code the following line should check for multiple forms:
    $applicable_form_ids = array(123, 456, 789);

    Also the following change should add the prefix:

     if ( $response['success'] ) {
                            $entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $module_id );
                            // Add prefix before entry_id
                            $prefixed_entry_id = 'ORTI2024' . $entry->entry_id;
                            update_post_meta( $this->new_post, 'CUSTOM_FIELD_NAME', $prefixed_entry_id );
                        }

    However, please do make sure to test the above code in a staging or a test site before you apply it in the live site.

    Kind Regards,

    Nithin

    Thread Starter ejaganece

    (@ejaganece)

    Thanks a lot it’s working.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Set Form Title as Category in CPT with ACF’ is closed to new replies.