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 on root of your web server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php // include wordpress file define( 'WP_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 http://onlinecode.org/save_data.php 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.
For more visit :: onlincode.org