Incrementing counter issues
-
Hi – I’m not sure if this is a CFDB issue or not – likely not.
But I’m hoping to get some pointers to where I could investigate to find the cause of my issue.
I have added a counter which increments each time a form is submitted. I followed snippets posted by the developer of the Dynamic Text Extension plugin. My functions.php code is this.
/**** Customer id ****/ //Define the key to store in the database define( 'CF7_COUNTER', 'cf7-counter' ); //Create the shortcode which will set the value for the DTX field function cf7dtx_counter(){ $val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count return $val; } add_shortcode('CF7_counter', 'cf7dtx_counter'); //Action performed when the mail is actually sent by CF7 function cf7dtx_increment_mail_counter(){ $val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count update_option(CF7_COUNTER, $val); //Update the settings with the new count } add_action('wpcf7_mail_sent', 'cf7dtx_increment_mail_counter');I then use a DTX shortcode to have the counter as a hidden field on the CF7 form and it gets stored by CFDB.
This allows us to have a unique id for each customer contact.
The problem is that sometimes (I haven’t figured out reproducible conditions), the counter does two odd things. I have seen a couple of instances where the id included in the emails and stored by CFDB is not incremented – two consecutive records, same id. Then the next record is +2 – so the counter appears to be incrementing but is not in the emails or CFDB.
I’ve only seen the second weird behaviour once (today) and that is that the id included in an email and in CFDB jumped backwards. i.e. the ids were 134219, 134220, 134221, 134220, 134223
Again, the counter appears to have incremented but the value in the emails and CFDB is different.
Note that the contact forms with recorded ids of 134220 were sent at very different times (actually 4 hours apart).
Any ideas as to what’s going on?
Thanks
Stuart
The topic ‘Incrementing counter issues’ is closed to new replies.