• Resolved shilux

    (@shilux)


    Good day, wonder if you can help,

    I have a form that i am using to create Capture Event Bookings.

    I am looking for a way to use the Hidden field to generate a Unique identifier (Can be a long submission ID) which I will be using as a Booking Number for each submission. The Unique identifier can be between 4 to 6 Characters long. Even if it can be the submission ID just longer with leading numbers ie 000000128.

    Thank you

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

    (@wpmudevsupport14)

    Hi @shilux,

    I hope you are keeping well and thank you for reaching out to us.

    The following workaround should help you with this requirement.

    Please download the zip file from the following link: https://gist.github.com/wpmudev-sls/5c8213b37d4ef2730c57e3822c3fe5a7. Extract the contents and upload the file named “wpmudev-forminator-hidden-input-random-number.php” to your site’s wp-content/mu-plugins folder. If this folder doesn’t exist, you can create it following the instructions provided here: https://premium.wpmudev.org/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins.

    Please update the form ID and the hidden field ID to match your form.

    I hope that helps. Let us know how it went!

    Kind Regards,
    Nebu John

    Thread Starter shilux

    (@shilux)

    Hi There,

    Thanks you for the code, it works like a charm

    Thread Starter shilux

    (@shilux)

    Just a follow-up question, if I wanted to have this function on 2 forms and 2 hidden field would i just have to update the following lines of code
    would i just need to comma separate the
    hidden field id and form id

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @shilux

    I hope you are doing well.

    Unfortunately, it is not that simple, but to make sure we are on the same page, you would have two hidden fields in a single form or it is a mapping for example:

    $field_mapping = [ 'form_id' => 'hidden-1']

    Best Regards
    Patrick Freitas

    Thread Starter shilux

    (@shilux)

    Sorry am not much a dev
    Yes 2 hidden fileds in in a single form both generating Random numbers

    If random number generator is not possible is there some sort of Query parameter that i can run in the hidden field to maybe combine fields or 2 number together to make one output field Using hidden field query paramate ie {date_ymd}+{user_id} Submission Date (full date without separater ie 20240306) + Submission ID

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @shilux

    Thank you, no worries

    We escalated this to our second line support team to verify if we can extend that code or find a solution, we can’t guarantee due to our support scope but we will take a look.

    We will keep you posted.
    Best Regards
    Patrick Freitas

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @shilux ,

    Please try the following code:

    <?php
    
    add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_change_hidden_field_data_random', 10, 3 );
    function wpmudev_change_hidden_field_data_random( $entry, $module_id, $field_data_array ) {
        $form_ids = array(1609); // Please change the form ID.
    	if ( !in_array( $module_id, $form_ids ) ) {
    		return;
    	}
        
        foreach ( $field_data_array as $key => $value ) {
            if ( strpos( $value['name'], 'hidden-' ) !== false && $value['value'] == 'random_id' ) {
                Forminator_CForm_Front_Action::$info['field_data_array'][$key]['value'] = sanitize_text_field( date_i18n( 'Ymd', forminator_local_timestamp(), true ) . $entry->entry_id );
            }
        }
    }

    Note: The hidden field should be added like the attached image, the default value should be custom value and in custom value, random_id text should be used. Also, in the snippet form ID 1609 should be changed to your form’s ID.

    https://monosnap.com/file/4jJapBSJ4HEXsFSo4lDtjFbx0h68vB

    See how to create and use mu-plugins https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins
    Make sure to take a backup before making any changes to your site.

    kind regards,
    Kasia

    Thread Starter shilux

    (@shilux)

    Hi Kasia,

    Thanks for the code. Do i add this aas new code or update the prebiously submited code

    Thread Starter shilux

    (@shilux)

    WOW The code works like magic.
    Thank you so much for all the help

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘UNIQUE IDENTIFER FOR FORM SUBMISSIONS’ is closed to new replies.