php – gravityforms – export submitted entries counter (per user) on csv export

Question

I can’t solve a problem with gravityforms.
In the website users are registering into form1, after this they are able to submit another form (form2) with things inside.

Basically I would like to export the number of submitted forms (form2) per user, so in my csv file i can see something like:

userid, user name, email, sumbitted forms
1, myname, my@email.com, 4
2, hisname, his@email.com, 2
3, hername, her@email.com, 1

and so on..

To see on any page how many forms user have submitted I’m using gravitywp_count which is giving me handy shortcode to do so. For example to see how many forms the user has submitted I just simply add a shortcode like [gravitywp_count formid='1'  created_by='1'] (to filter submissions of form with id 1, by user with id 1)

I guess the easiest way would be to be able to populate an invisible field inside the form2 with the output from the shortcode (using created_by='current' to retrieve the currently logged user which is submitting the form) so that just by activating the hidden field on the export section I’d achieve my goal. the question is: can I populate an hidden field with the output value of the shortcode???

I was also tinkering with code, but I’m not experienced enough to get it done.
What I was trying to do was something like this, according to the documentation of gravityforms (which I barely understand)

this to add a field to the field selection list

add_filter( 'gform_export_fields', 'add_fields', 10, 1 );
function add_fields( $form ) {
    array_push( $form['fields'], array( 'id' => 'counter', 'label' => __( 'Counter', 'gravityforms' ) ) );
 
    return $form;
}

but then to get the value I need I get stuck.
I know I can count entries with
GFAPI::count_entries( $form_id, $search_criteria )
but I really can’t make it work..

add_filter( 'gform_export_field_value', 'set_export_values', 10, 4 );
function set_export_values( $value, $form_id, $field_id, $entry ) {
   $value = xxxxxxxxx.... /* can't find a working thing to put in here.. */
   return $value;
}

Any help would be lifesaver.
Thanks

0
mosfettis 5 months 2022-04-20T11:39:53-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse