cURL cannot insert company name with special characters
This is the php script I am using to insert data from QuForm to Zoho. It works fine until a user types in a special character in their company (for example Smith & Smith).
When & is used, the insert does not show up in zoho.
We tried replacing $company = $_POST['iphorm_1_3']; with $company = urlencode($_POST['iphorm_1_3']) ; But the company name shows up with ASCII codes for & (Smith+%26%Smith).
Any suggestion on how to make this work with Zoho?
- function post_to_zoho($form)
- {
- // Find the field unique ID
- // http://support.themecatcher.net/quform-wordpress/guides/basic/finding-the-unique-element-id
- // and Replace field ids iphorm_XX_XX
- $company = $_POST['iphorm_1_3'];
- $lastname = $_POST['iphorm_1_1'];
- $email = $_POST['iphorm_1_2'];
- $phone = $_POST['iphorm_1_8'];
- $city = $_POST['iphorm_1_25'];
- $country = $_POST['iphorm_1_4'];
- $qty = $_POST['iphorm_1_5'];
- $product = $_POST['iphorm_1_16'];
- $licenseown = $_POST['iphorm_1_6'];
- $count = count($product);
- if ($count > 0)
- {
- $product = implode(" ", $product);
- }
- // Zoho Api End Point
- $url = 'https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1';
- // Build Lead Data XML
- // Add or Remove Lead Fields.
- $leadinfo = "<Leads>" .
- '<row no="1">' .
- '<FL val="Last Name">'. $lastname . "</FL>" .
- '<FL val="Company">'. $company . "</FL>" .
- '<FL val="Email">'. $email . "</FL>" .
- '<FL val="Phone">'. $phone . "</FL>" .
- '<FL val="City">'. $city . "</FL>" .
- '<FL val="Country">'. $country . "</FL>" .
- '<FL val="Qty">'. $qty . "</FL>" .
- '<FL val="Product">'. $product . "</FL>" .
- '<FL val="License own">'. $licenseown . "</FL>" .
- "</row>" .
- "</Leads>" ;
- // Prepare Curl Request Params
- $params = array(
- 'authtoken' => "XXXXXXXXXXXXXXX",
- 'scope' => "crmapi",
- 'xmlData' => $leadinfo
- );
-
- // Initialise CURL
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FAILONERROR, true);
- // Post data
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_URL, $url);
- // Call
- $output = curl_exec($ch);
- // Analyse result
- if ($output === false) {
- $output = sprintf("CURL error (#%d) \"%s\". Requested URL was \"%s\".", curl_errno($ch), curl_error($ch), $url);
- }
- curl_close($ch);
- }
- add_action('iphorm_post_process_1', 'post_to_zoho', 10, 1);