WordPress.org

Support

Support » Plugins and Hacks » Contact Form DB » add ID for each submission

add ID for each submission

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

    @msimpson

    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.

    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 ?

    and how can you export the submit_time field, please ?

    Plugin Author Michael Simpson

    @msimpson

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

    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

    Plugin Author Michael Simpson

    @msimpson

    To add a field, see this post.

    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.

    Plugin Author Michael Simpson

    @msimpson

    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"]

    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”

    Plugin Author Michael Simpson

    @msimpson

    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

    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

    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 ??

    Plugin Author Michael Simpson

    @msimpson

    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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘add ID for each submission’ is closed to new replies.
Skip to toolbar