Reputation: 1601
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?
Upvotes: 2
Views: 3688
Reputation: 3614
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.
Upvotes: 2