2

I have installed "contact-form-7" plugin and using "Contact Form Submissions" to save data in the database (https://wordpress.org/plugins/contact-form-submissions).

Also, I have created a form with same fields in a mobile app. I am using "WordPress REST API (Version 2)" (https://wordpress.org/plugins/rest-api) for APIs.

Now my question is that I want to save mobile form data using "WordPress REST API (Version 2)" and display in wp-admin in Contact -> Submissions page. Will any suggestion be good?

Sunny Jangid
  • 578
  • 4
  • 19
Maulik patel
  • 1,551
  • 8
  • 22
  • 44

1 Answers1

2

Contact form submission save data into wp_posts table as post type ='wpcf7s'

You can get data from api methods and inside rest hook you can insert post by:

$form_post = array(
  'post_title'    => 'random post title',
  'post_content'  => 'Client IP:(Client IP:)',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_type' => 'wpcf7s'
);

$id = wp_insert_post( $form_post );

It will return post id and then you can store additional meta key / value into wp_post_meta table.

Below are meta keys:

sender
recipient
additional_headers
wpcf7s_posted-Message
subject
form_id

Form ID should be ID of form created in admin.

Ashish Patel
  • 3,551
  • 1
  • 15
  • 31