Viewing 1 replies (of 1 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    If you don’t care what the number looks like (like an alpha numeric string like “4b3403665fea6” is OK) then you could use PHP uniqid() function to add an ID field on form submission:

    See: https://cfdbplugin.com/?page_id=747

    function add_id_field($formData) {
        $formData->posted_data['ID'] = uniqid();
        return $formData;
    }
    add_filter('cfdb_form_data', 'add_id_field');

    You might also want to check $formData->title in the code to see if it is one of the forms that want to do this for, instead of all of them.

    If you want an 1-up counter, then I think you will need to create a table in your MySQL DB with an integer field that is AUTOINCREMENT. In the function above you $wpdb->insert() a row and get a new number returned each time. Then use that value instead of uniqid().

Viewing 1 replies (of 1 total)
  • The topic ‘Add Unique number to each form submission (not depending on the form used)’ is closed to new replies.