0
votes

I created a custom form in Wordpress where user fill some input fields and on submitting the form, now the recepient is getting mail. What I need is when user submits the data, the data should gets stored into the contact form DB. With Contact Form 7 plugin, all the data is stored, but I need to store the custom contact form data into the contact form 7 db.

Can you please help me to find a possible solution for the same?

1

1 Answers

0
votes

Finally, found the exact solution.

If we want to programatically push data into the Contact Form DB, there are two basic things you will need to know:

How to struture your form data so that the plugin knows how to consume it
How to call the plugin’s save data function

Data should be structured like this:

$data = (object)  array(
    'title' => 'form-name',
    'posted_data' => array(
    'fname' => $_POST['fname'],
    'lname' => $_POST['lname'],
    'email' => $_POST['email']);

Where ‘form-name’ is the name of the form, and ‘fname’, ‘lname’, and ’email’ are form fields in this example. Replace them with the fields from your form.

Calling the Plugin

require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CF7DBPlugin.php');
$plugin = new CF7DBPlugin();
$plugin->saveFormData(&$data);

OR Use CF7's hook

do_action_ref_array( 'wpcf7_before_send_mail', array( &$data) );

The advantage of using CF's hook is that that we do not need to include the CF7DBPlugin.php file, it is a de-coupled approach. The disadvantage is that any other plugin listening to the hook will also get the data.