Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected $allowAnonymous = array('actionPostLead');
- public function actionPostLead()
- {
- $this->requireAjaxRequest();
- // Initialize the $kv array and query var for later use
- $kv = array();
- $query_string = '';
- //If there are POST variables
- if ($_POST) {
- // For each POST variable as $name_of_input_field => $value_of_input_field
- foreach ($_POST as $key => $value) {
- // Set array element for each POST variable (ie. first_name=Arsham)
- $kv[] = stripslashes($key).'='.stripslashes($value);
- }
- // Create a query string with join function separted by &
- $query_string = join('&', $kv);
- }
- // Check to see if cURL is installed ...
- if (!function_exists('curl_init')) {
- die('Sorry cURL is not installed!');
- }
- // The original form action URL from Step 2 :)
- $url = 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
- // Open cURL connection
- $ch = curl_init();
- // Set the url, number of POST vars, POST data
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, count($kv));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
- // Execute SalesForce web to lead PHP cURL
- $result = curl_exec($ch);
- // close cURL connection
- curl_close($ch);
- if ($result) {
- $this->returnJson(array('success' => true));
- } else {
- $this->returnErrorJson($e->getMessage());
- }
- }
- $.ajax({
- type: 'POST',
- url: '/',
- data: data,
- dataType: 'json',
- success: function(response) {
- formBlock.removeClass('submitting');
- var successMessage = $('.formBlock.on').data('success-message');
- showFormSuccessBanner(successMessage);
- hideForm(id);
- },
- error: function(err) {
- console.log("Error");
- console.log(err);
- formBlock.removeClass('submitting');
- }
- });
Add Comment
Please, Sign In to add comment