How can I add a permanent variable to a Wordpress form and change it in future

53 Views Asked by At

There are several questions about this with several replies but (being a newbie to Wordpress & PHP etc) either I don't understand the replies or, when I do, the solutions don't work. Could someone give me a very simple answer to a very simple question, please, preferably with actual code that I can cut and paste.

I have a Wordpress form with a reference number field. I want to store this in a variable, starting at 1, say, and then every time someone opens the form and starts to fill it in, the current value of the variable is retrieved, put in the form and incremented - to 2 in this case. When they have completed the form, they submit it, I get an email and the form with their data no longer exists. When the next person opens the form, their reference number is 2 and so on.

In my naivete, I would think that Wordpress could provide this functionality as it is so simple. If not, a simple php function in functions.php, callable from my Wordpress form, should do the job.

Thanks for considering such a naive question.

1

There are 1 best solutions below

1
Dendenzilla On

I believe this could solve your problem: https://medium.com/@codefoxx/how-to-count-the-number-of-visits-on-your-website-with-html-css-javascript-and-the-count-api-2f99b42b5990

If you need help with implementation I'll gladly help.