There are numerous plugins available to save and view the cf7 submission in the dashboard. If you want to ignore the plugin and write your own code to save the cf7 then follow this article.
I am using ACF fields to store the data submitted from cf7.
1. First, create an ACF options page. I am creating Cf7 Submissions as my options page where I will list all my form submissions values
if( function_exists('acf_add_options_page') ) { acf_add_options_page([ 'page_title' => 'Cf7 Submissions', 'menu_title' => 'Cf7 Submissions', 'redirect' => false ]); }
2. Create a form using CF7. I am using the default form cf7 provides
3. Create a repeater field in ACF to save the form submitted values in the database and assign it to the CF7 Submissions options page
4. CF7 provides hook wpcf7_before_send_mail which enables us to process the submitted data the way we like before submitting the form. I am using this hook to save the form submission in the dashboard
add_action("wpcf7_before_send_mail", "app_send_email", 10, 1); function app_send_email($wpcf){ // get current SUBMISSION instance $submission = WPCF7_Submission::get_instance(); if(!$submission) return $wpcf; // get submission data $data = $submission->get_posted_data(); /* * I have created the matching field name in the database, * so that I don't get confused with the form field name and database fields where I am storing my data's */ $dataToSave = [ 'your-name' => $data['your-name'], 'your-email' => $data['your-email'], 'your-subject' => $data['your-subject'], 'your-message' => $data['your-message'] ]; saveSubmissionToAcf($dataToSave); return $wpcf; } function saveSubmissionToAcf(array $newSubmission){ $oldSubmission = get_field("cf7_submission", "option"); if(!$oldSubmission) $oldSubmission = []; $formSubmittedValues = array_merge($oldSubmission, [ $newSubmission ]); update_field( "cf7_submission", $formSubmittedValues, "option" ); }
Note: Add all the codes as mentioned earlier in your function.php
5. update_field updates the values in the database
We are capturing the previously submitted data so that we can merge it with the new submitted form values.
Note: The previously saved data in the repeater fields are lost if we don’t merge and update it with the new data submitted by the form
6. Check the CF7 submission options page to see the lists of saved submitted form fields in the dashboard
Views: 159