• Resolved rpalex

    (@rpalex)


    Is it possible to create a Unique ID (UID) field or Ticket Number using values from the Form and a sequential number that is incremented when a new form is submitted.

    For example, there will be a drop down field with few options.
    If an Option is selected, the default value will be predefined acronymn
    Ex.
    Hidden field: sequential number that starts at 100. So the next form will get 101.
    If Option 1 selected, set UID = E-AB-101
    If Option 2 selected, set UID = E-AG-101
    If Option 3 selected, set UID = W-AN-101
    and so on…

    This is likely a case where I have to hand code the algorithm. But is it possible to read the values of the dropdown from the Form and use that information to create this UID?

    Any help would be appreciated.

    • This topic was modified 2 years, 9 months ago by rpalex.
Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @rpalex

    I hope you are doing good today.

    Please check this thread which will possibly help here as well:
    https://www.ads-software.com/support/topic/give-user-an-id-after-form-summited/

    Kind Regards,
    Kris

    Thread Starter rpalex

    (@rpalex)

    Hi Kris,
    Do I need to install WPMU DEV Plugins or purchase Hub or something to get the code installed? I didn’t quite understand what I need to do there in this page
    https://wpmudev.com/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins

    Thank you
    Rej

    • This reply was modified 2 years, 9 months ago by rpalex.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @rpalex

    I hope you are doing well.

    You need to install the code as mu-plugin, it is a native WordPress feature https://www.ads-software.com/support/article/must-use-plugins/ the article shows how to install it.

    Basically create a mu-plugins folder inside the wp-content folder and place the PHP file inside this new folder.

    Best Regards
    Patrick Freitas

    Thread Starter rpalex

    (@rpalex)

    Hi Pat,

    For this, I did exactly what you recommended. Created a Hidden field {hidden-1} and then copies the code from https://gist.github.com/wpmudev-sls/e3e4655e9ad74686051393a1d0ed5ffa to a file called wpmudev-forminator-unique-identifier.php in the mu-plugins folder.

    Then I also updated the line 164 with my information as follows:
    public function wpmudev_randomizer( $form_id = 2763, $form_field = 'hidden-1' ) {

    But nothing happened.

    Here’s what the Inspect Console returned:

    document.getElementById("hidden-1").value
    ""
    document.getElementById("hidden-1")
    <input id="hidden-1" type="hidden" name="hidden-1" value="">

    1. Where am I supposed to see the Unique code?

    2. What should I be setting up the {hidden-1} to be. It has some preset values, and i have to select one… which value should I be selecting for that?

    3. How can I use the values from one of my form fields to be appended to make up the Unique ID string.

    Thank you.

    • This reply was modified 2 years, 9 months ago by rpalex.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @rpalex

    Thanks.

    The code will handle after submission so you won’t see it in the browser console, but after the submission:

    https://monosnap.com/file/TAvXquSxGnJ8KN7an1M6puwM3cqWnb

    You don’t need to edit line 164, those are default parameters in case no parameter is sent when calling the function, so you can keep like the github version.

    Only line that needs to be edited is

    // User defined settings
            private $forms = array(
                393 => 'hidden-1',
                200 => 'hidden-2',
                // ... more (form_id) - (hidden_field) pairs here
            );

    To match your Form ID to Field ID.

    Best Regards
    Patrick Freitas

    Thread Starter rpalex

    (@rpalex)

    Okay… thank you. So I made those changes and I can see a value getting stored in to the Hidden field, and that is great!

    In my case, I got the value “1E7M0Q” and for the second test I got the value “7KP2NI”. Clearly they are Unique IDs.

    But how do we customize it a bit more so that it is a meaningful unique ID similar to what I have mentioned in the original post.

    For example, there will be a drop down field with few options.
    If an Option is selected, the default value will be a pre-defined acronym
    The drop down options will be
    Option 1: E-AB
    Option 2: E-AG
    Option 3: W-AN
    Option 4: W-AT
    Option 5: W-BR
    and so on…

    And the User selects…
    User 1 selects: Option 1, UID will be = E-AB-101
    User 2 selects: Option 1, UID will be = E-AB-102

    User 3 selects: Option 3, UID will be = W-AN-103
    User 4 selects: Option 3, UID will be = W-AN-104
    User 5 selects: Option 3, UID will be = W-AN-105

    User 6 selects: Option 4, UID will be = W-AT-106
    User 5 selects: Option 1, UID will be = E-AB-107
    and so on…

    In this example, E is EASTERN REGION, AB is one office in the E, 101 is one application, E-AG would be another office in the E and 102 would be the second application submitted.

    Is it possible to introduce this customization in to the Unique ID value. This would essentially require us to read the value of the Dropdown from the form and also somehow look at the next sequential number also. Perhaps that could simply be a text file in the mu-plugin folder or elsewhere, populated with just the next number in the sequence that the script will use to create the UID, and it will update the text file with the next number for the transaction coming up!

    • This reply was modified 2 years, 9 months ago by rpalex.
    • This reply was modified 2 years, 9 months ago by rpalex.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @rpalex

    I am afraid it will require a deep development which would be out of our scope, but the function that generates the ID is located at line 164 https://gist.github.com/wpmudev-sls/e3e4655e9ad74686051393a1d0ed5ffa#file-wpmudev-forminator-unique-identifier-php-L164

    You will also need to handle the other data from other fields and pass it as a parameter to this function.

    Best Regards
    Patrick Freitas

    Thread Starter rpalex

    (@rpalex)

    Hi Pat,

    1. What can I do to simply change the Unique ID to just numeric numbers and incremental, without the use of any field values from the Form? So the numbers would be, say, 10000, 10001, 10002, and so on.
    If I remove the Alphabets from this command, would that help?
    $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

    I tested that and it will limit the output to just numbers. But the challenge is make it sequential!!!

    2. What would be the command to READ the value of a form field? If I wanted to read the value of {name-1}, can I just include that to the following code as shown below

    
            // User defined settings
            private $forms = array(
                2763 => 'hidden-1',
                2763 => 'name-1',
                200 => 'hidden-2',
                // ... more (form_id) - (hidden_field) pairs here
            );
    

    And then modify line 164, as
    public function wpmudev_randomizer( $form_id = 0, $form_field = 'hidden-1', $form_field = 'name-1' ) {

    Any help would be appreciated.
    Thank you.

    Plugin Support Adam – WPMU DEV Support

    (@wpmudev-support8)

    Hi @rpalex

    Removing letters from $characters variable will remove characters from identifier, leaving only numbers, but it doesn’t change the way numbers are generated.

    For them to be sequential you’d need entire block of additional code that would (before generating number) read DB to find the highest already generated one. So basically, instead of this line (no 166)

    $num = '';

    you’d need a code that would search through DB entries/submissions. Then the rest of randomizer code could be actually removed as all you’d need would be to increment such number but I’m afraid such additional code really goes out of the scope of this support.

    The solution that we shared is a good foundation for further development but that’s, I’m afraid, as far as we can go with this as.

    Kind regards,
    Adam

    Thread Starter rpalex

    (@rpalex)

    Okay Thanks Adam.

    Yes, it is understandable that you can only provide support to certain extent and thank you for the support so far. We will attempt to work with the foundation that you provided.

    Is there any code samples that we can examine to see how data values are read from the DB?

    Also, which database holds the ID and the submissions? I see <hostname>frmt_form_entry_meta holding most of the data, but couldn’t spot the ID field.

    And is there a way to limit the Script provided to just one form. Now, when I modify, if there is an error, it affects all forms and in fact in couple of instances, it affected the whole site – I couldn’t load the site. Is there anyway we can limit this mu-plugins to only affect one form?

    And if you could point to any documentation or examples on how to read a DB value etc that would be a great help.

    Thank you!

    • This reply was modified 2 years, 8 months ago by rpalex.
    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @rpalex,

    Is there any code samples that we can examine to see how data values are read from the DB?

    You can check the API docs for more info:
    https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/

    Also, which database holds the ID and the submissions? I see <hostname>frmt_form_entry_meta holding most of the data, but couldn’t spot the ID field.

    It would be the wp_frmt_form_entry_meta as you have stated. There should be an “entry_id” meta key in the table which holds the ID.

    And is there a way to limit the Script provided to just one form. Now, when I modify, if there is an error, it affects all forms and in fact in couple of instances, it affected the whole site – I couldn’t load the site. Is there anyway we can limit this mu-plugins to only affect one form?

    The snippet only works based on the form ID, so it’ll only work if you define a specific form ID where the code should work.

    You can find that condition on line 26 of the code:
    https://gist.github.com/wpmudev-sls/e3e4655e9ad74686051393a1d0ed5ffa#file-wpmudev-forminator-unique-identifier-php-L26

    Where the code:

    private $forms = array(
                100 => 'hidden-1',
                200 => 'hidden-2',
                // ... more (form_id) - (hidden_field) pairs here
            );

    Where 100,200 in the above are form ID, and the snippet will only work for that specific form added and shouldn’t affect any other form nor your website.

    I hope this helps in moving forward.

    Kind Regards,
    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @rpalex ,

    We haven’t heard from you for a while now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Unique Custom Identifier Field’ is closed to new replies.