Hi @webteamkrusty
I hope you’re well today and thank you for your question!
I’ve got a working code for you that you can use to achieve this. It’s actually quite customizable so you can set you reference number format in various ways but for the format of “YEAR_number” you’ll need to do one small change.
You’ll find the code here
https://gist.github.com/adczk/fbf06b6abf7753df6b37234b13041e79
and here is how to use it:
1. remove those custom codes that you already tried first
2. edit your form and
– add a file of type “hidden” to it
– make sure that this file has its “Default Value (optional)” option set to “Custom Value”; no need to put anything in “Custom Value” field though.
– note down field id (e.g hidden-1)
– edit your inline “thank you” message and add this to your “thank you” text where you want number to appear
{formatted_value}
– update form
3. create an empty file with a .php extenions (e.g “forminator-auto-reference-number.php”)
4. copy and paste code that I shared into that file
5. configure the code
a) in this line
private $field_name = 'hidden-1';
set the hidden field ID (if it’s different than hidden-1) that you’ve previously added to the form
b) in this line
private $form_ids = array( 1483 );
replace the number 1483 with an ID of your form; it’s the same number that you see in form’s shortcode
c) you can configure other settings according to comments in code but that’s optional
d) replace this line (way down the code)
$formatted_value = $this->prefix . $formatted_value . $this->suffix;
with these two lines
$this->prefix = date('Y').'_';
$formatted_value = $this->prefix . $formatted_value . $this->suffix;
6. save the file and upload it (using FTP or similar way) to the “/wp-content/mu-plugins” folder of your site’s WordPress installation; if there’s no “mu-plugins” folder inside “wp-content”, just create empty one first.
If everything’s set up correctly this should work out of the box and:
– thank you message would display the generated reference number
– the same number will be saved in submission as value of the hidden field that you added to form
– you can also include it in e-mail notifications (if all fields are included, it will be there out of the box; if you use individual fields, just include that hidden field).
The code was created some time ago already but I just tested it a few minutes ago and I can confirm it still works fine.
Best regards,
Adam