WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form DB
add ID for each submission (14 posts)

  1. archiparmentier
    Member
    Posted 1 year ago #

    How can i add a unique ID for each submission. I need just to add ID in the csv export and the page admin.php?page=CF7DBPluginSubmissions.

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

  2. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    If you export the submit_time field, you will get a unique number for each submission. It is just a numeric representation of the "Submitted" field.

    Or if you want to generate your own id, that is more complicated and you would need to read this.

  3. archiparmentier
    Member
    Posted 1 year ago #

    thanks mickael !
    but i need just a unique number for each submission, like an auto_icrement field, simply
    is it possible to add an "auto_increment" field ?

  4. archiparmentier
    Member
    Posted 1 year ago #

    and how can you export the submit_time field, please ?

  5. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    Create an export link from the Short Code builder admin page. Put "submit_time" and the other fields you want in the "show" field.

  6. archiparmentier
    Member
    Posted 1 year ago #

    Thank you very much Michael.
    I could probably add a simply auto_increment field. No ?
    How can i do ?

    PS : i try to change the name of my fields but that doesn't work. The name is ex_field_1

  7. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    To add a field, see this post.

  8. archiparmentier
    Member
    Posted 1 year ago #

    To use the submit_time as ID, i use this code :

    function myFilter($formData){
        $formName = 'Form: 1';
        if ($formData && $formName == $formData->title) {
            $formData->posted_data['identifiant'] = $formData->posted_data['submit_time'];
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'myFilter');

    And to display the TABLE i use this shortcode :
    [cfdb-datatable form="Form: 1" show="identifiant" role="Administrator"]
    but the row 'identifiant' is empty.
    How can i have a row ID populated with the submit_time ? Thank you very much.

  9. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    The code looks correct assuming form name is correct.

    You can just use submit_time directly:
    [cfdb-datatable form="Form: 1" show="submit_time" role="Administrator"]

  10. archiparmentier
    Member
    Posted 1 year ago #

    if i use this shortcode
    [cfdb-datatable form="Form: 1" show="identifiant" role="Administrator"]
    the name of the row is "identifiant" but the row is empty

    if i use this shortcode
    [cfdb-datatable form="Form: 1" show="submit_time" role="Administrator"]
    the row is not empty but its name is "submit_time"
    I need to replace "submit_time" by "identifiant"

  11. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    Reasons why you might get no rows
    1. wrong form name
    2. no submissions in DB
    3. "show" refers to non-existent field
    4. not logged in with user that has "role" priviledges

    Try reducing the short code to just
    [cfdb-datatable form="Form: 1"]
    to see if you get rows. If no rows check 1 & 2.
    If you get rows, add the "show", check 3
    If that works, add the "role", check 4

  12. archiparmentier
    Member
    Posted 1 year ago #

    when i use this shortcode :
    [cfdb-datatable form="Form: 1"]
    i have all rows. The row "identifiant" exist, but this row is empty.

    when i use this shortcode :
    [cfdb-datatable form="Form: 1" show="identifiant"]
    i see just one row : "identifiant" but this row is empty

  13. archiparmentier
    Member
    Posted 1 year ago #

    if i replace this code

    function myFilter($formData){
        $formName = 'Form: 1';
        if ($formData && $formName == $formData->title) {
            $formData->posted_data['identifiant'] = $formData->posted_data['submit_time'];
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'myFilter');

    by this code

    function myFilter($formData){
        $formName = 'Form: 1';
        if ($formData && $formName == $formData->title) {
            $formData->posted_data['identifiant'] = 'test';
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'myFilter');

    the row "identifiant" is not empty and the value is "test".

    Are you sure it's possible to populate the row "identifiant" with the values of the raw submit_time ??

  14. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    OK, I now realize a couple things:

    1. "submit_time" is not available to your filter code. That will not be generated until after the filter is run but right before it is saved in the DB. That is why you are getting a blank identifiant field.

    You might instead generate your own unique id like:
    $formData->posted_data['identifiant'] = uniqid();

    2. When you show="identifiant" you will only gets rows that have a identifiant value. In your case you have only one row because only one form submission was made that has an actual value for identifiant (although that value is a blank). All other rows do not have an identifiant field.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.