Reputation: 525
I'm trying to achieve the following. I would ask the visitor to complete an inquiry form by providing their name and record the current date and other questions.
Then I would generate a unique reference number by using the date(day+month) and the first two alphabets of their name. The reference number will be added to the email sent out to admin and visitor upon request.
Example, the form is completed on 09042019, and the name is Jonhny, so the unique reference number would be 0903JO, how can I achieve this?
I'm looking at Contact Form 7 Dynamic Text Extension plugin but I'm not sure if I can achieve this with the plugin.
I have also go through a suggestion by AMCD at here https://wordpress.org/support/topic/contact-form-7-generating-reference-number but from my understanding, it generates a random reference number which is not my case.
I have also go through this similar topic here Return a unique number to the customer after apply on our form (wordpress) but it doesn't do what I need.
Hoping expert here could help.
Thank in advance
Upvotes: 0
Views: 2718
Reputation: 525
I have got the answer to my question by posting the questions separately.
There is 2 information needed to be collected.
1) date
2) name
1) to get the current date, add the following script & code:
<script>
jQuery(function ($) {
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = now.getFullYear()+"-"+(month)+"-"+(day);
$('#datePicker').val(today);
$("#datePicker").attr("min", today);
});
</script>
And call it with
[date* today-date max:today class:required id:datePicker]
Add the max:today
to prevent guest from picking date later than today.
Thanks to jer23jk from this post Contact Form 7: Set default date to today
2) Now we need to display the first 2 characters of the name. Thanks to Howard E for his help from this post Contact Form 7: Set default date to today
Please visit the above link for the complete answer from Howard E.
I have adapted to my project as the following :
<script>
jQuery('input[name="fullname"]').blur(function () {
var s = jQuery(this).val().substr(0, 2);
var t = s.toUpperCase();
if (jQuery('#fullname-mailtag').length) {
jQuery('#fullname-mailtag').val(t);
} else {
jQuery(this).after('<input name="fullname-mailtag" id="fullname-mailtag" type="hidden" value="' + t + '">');}});
</script>
Noticed I have added the uppercase function to make it more professional.
var t = s.toUpperCase();
Finally, add this to mail tab
Client Code: [_format_today-date "dm"][fullname-mailtag]
Hope this could help anyone looking to achieve the same result.
Upvotes: 3