Cognito forms API using wordpress
In this post we will show you Cognito forms API using wordpress, hear for Cognito forms API using wordpress we will give you demo and example for implement.
1) In this Cognito forms API using wordpress, we will simulate having a remote database in which we will be recording new entries. you most databases communicate data in a language/format known as “Sql”. Because Cognito Forms communicates data using JSON, we will need an intermediary program to handle this translation.
2) Create a small application which can capture data from a Cognito Forms(Cognitoforms) web hook and save that data to a database:
create file save_data.php ::
create file save_data.php on root of your web server
<?php // include wordpress file define( 'wpxs_USE_THEMES', false ); require( './wp-load.php' ); $json_data = file_get_contents("php://input"); if (empty($json_data)) { echo "No data found"; die; } // contact_data as object $contact_data = json_decode($json_data); if ($contact_data == null && json_last_error() !== JSON_ERROR_NONE) { echo "Error reading JSON data: " . json_last_error(); } // for call wordpress db global $wpdb; $insert_query = "insert into contact_datas (firstname,lastname,address_line1,address_line2,address_city,address_state,address_postalcode,phone,email,company,comments) values ('".$contact_data->{'Name'}->{'First'}."','".$contact_data->{'Name'}->{'Last'}."','".$contact_data->{'Address'}->{'Line1'}."','".$contact_data->{'Address'}->{'Line2'}."','".$contact_data->{'Address'}->{'City'}."','".$contact_data->{'Address'}->{'State'}."','".$contact_data->{'Address'}->{'PostalCode'}."','".$contact_data->{'Phone'}."','".$contact_data->{'Email'}."','".$contact_data->{'Company'}."','".$contact_data->{'CommentsOrQuestions'}."')"; // insert data $wpdb->query($insert_query); ?>
3) Configure your web server so that this script can receive an HTTP POST and insert the data into your database. For example, create a new script on your web server called, save_data.php, so that when a POST is made to the script is executed.
4) Enter the URL into the “Submit Entry Endpoint” option (located under “Post JSON data to a website” in your form’s Submission Settings) and save.
5) View your form and submit an entry.
6) Verify that the data was saved in the database.
Hope this code and post will helped you for implement Cognitoforms API using wordpress. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org