WordPress CFDB生成唯一的序列号

时间:2016-06-07 18:33:01

标签: php wordpress

我正在研究一种使用sevensparks方法生成数据库中唯一序列号的方法。联系表格DB改变表格数据的方法来实现这个目前

http://sevenspark.com/tutorials/how-to-create-a-counter-for-contact-form-7

http://cfdbplugin.com/?page_id=747

计数正在运行,但问题是只要很少有用户在隐藏文本字段中提交带有预输入值的表单,我将收到多次提交相同的ID。

例如。 0012,0012,0014,0015,0015,0017

所以我想添加一个while循环来检查cfdb中的值会更好,但是它还没有到达那里。反正有没有实现这个目标?

例如。在保存号码之前,请检查数据库。如果存在数字则添加增量;如果不存在则保存新号码。

//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');

//CFDB change form data before it is saved
function update_counter($formData) {
    // Change $formData
    $formName = 'Contact form 1'; // change this to your form's name
    if ($formData && $formName == $formData->title) {

        while ( $val === get_option( CF7_COUNTER, 0) ) {
            $val++;
            return $val;
        }
        update_option(CF7_COUNTER, $val); //Update the settings with the new count

    }
    return $formData;
}
add_filter('cfdb_form_data', 'update_counter');`

0 个答案:

没有答案