• Resolved stenpelzer

    (@stenpelzer)


    I’m trying to add a unique ID to the submission. All the fields that are submitted at once should have the same ID. Of course this is possible by just using the timestamp, but I would rather have a 100% unique ID.

    Now, it’s not that hard to do that by editing the core files of the plugin, but that’s not the way i would want to do that.

    In the file CF7DBPLugin.php after line 701 i can add:

    $my_post = array(
    		'post_type' => 'cf7_submits',
    		'post_content' => (int)$post[ 'form_id' ],
    	);
    	$submissionID = wp_insert_post( $my_post );

    and edit the query on line 727 to add this $submissionID.

    Now the real question is, how can i do this without editing the plugin’s files? Preferrably using hooks.

    https://wordpress.org/plugins/contact-form-7-to-database-extension/

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

    (@msimpson)

    The submit_time will be unique. I put some code it to avoid two posts being listed as coming in the same nanosecond.

    But if you would like to add your own field, follow Changing Form Data Before it is Saved.

    I see you are getting an id by creating a post. A simpler way is to call uniqid() which will give you a value like “57028a2b87363”. (But that is independent of ids generated by WP for posts).

    Thread Starter stenpelzer

    (@stenpelzer)

    Yes, that’s it!
    Thank you.

    @stenpelzer

    Can you provide the actual code that you placed in the function.php

    I am trying to assign unique ID to each individual that made a form submit.

    Plugin Author Michael Simpson

    (@msimpson)

    This should do it:

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

    @msimpson
    that worked I can see the unique ID in the database now under column “uniqueid
    But that ID is not posted to email via following <input type=”hidden” id=”uniqueid” name=”uniqueid” value=””>

    Plugin Author Michael Simpson

    (@msimpson)

    CFDB does not do the email. You would have to figure out how to add it via your form plugin instead so that it emails it (then CFDB should also save it without the above code).

    How about calling “uniqueid” with Google Tag manager is that possible?

    Plugin Author Michael Simpson

    (@msimpson)

    I’m not familiar with Google Tag manager.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Add unique ID to the insert query’ is closed to new replies.