Tapeix Posted November 22, 2015 Share Posted November 22, 2015 After hours of trying to code an external API for my website, I did not succeed. I hope someone can help me out getting this thing work. I need to have a script that creates a new client in WHMCS each time an user sends a new entry with Gravity Forms. For this solution, I've based a solution using those three documentaries below. Gravity Forms doc: https://www.gravityhelp.com/documentation/article/gform_after_submission/ WHMCS examle: http://docs.whmcs.com/API:Example_Usage WHMCS user parameters: http://docs.whmcs.com/API:Add_Client#External_API <?php # add_action( 'gform_after_submission_115', 'after_submission', 10, 2 ); # function post_to_third_party( $entry, $form ) { add_action("gform_post_submission", "set_post_content", 10, 2); function set_post_content($entry, $form){ $post_url = "#"; # URL to WHMCS API file $username = "#"; # Admin username goes here $password = "#"; # Admin password goes here # $result = $this->ParseResponse( $response ); # return $result; if($form["id"] == 115) //Full register $postfields["action"] = "addclient"; $postfields["firstname"] = $entry["1.3"]; $postfields["lastname"] = $entry["1.6"]; $postfields["companyname"] = $entry["1.3"]; $postfields["email"] = "demo@whmcs.com"; $postfields["address1"] = "123 Demo Street"; $postfields["city"] = "Demo"; $postfields["state"] = "Florida"; $postfields["postcode"] = "AB123"; $postfields["country"] = "US"; $postfields["phonenumber"] = "123456789"; $postfields["password2"] = "demo"; $postfields["language"] = "Dutch"; # "firstname" => $entry["1.3"], # "lastname" => $entry["1.6"], # "email" => $entry["3"], # "address1" => $entry["2.1"], # "city" => $entry["2.5"], # "state" => $entry["2.4"], # "postcode" => $entry["2.3"], # "country" => $entry["2.6"], # "phonenumber" => $entry["4"], # "password2" => $entry["5"] # ); $request = new WP_Http(); $response = $request->post( $post_url, array( 'action' => $action ) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $data = curl_exec($ch); curl_close($ch); $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } if ($results["result"]=="success") { # Result was OK! } else { # An error occured echo "The following error occured: ".$results["message"]; } } Unfortunately, it doesn't work. Who can help me out of this? Thanks! 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 22, 2015 Share Posted November 22, 2015 you can email me here with more information about this request. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.