cURL cannot insert company name with special characters

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?
  1. function post_to_zoho($form)
  2. {    
  3.     // Find the field unique ID 
  4. // http://support.themecatcher.net/quform-wordpress/guides/basic/finding-the-unique-element-id
  5. // and Replace field ids iphorm_XX_XX 

  6. $company = $_POST['iphorm_1_3'];
  7. $lastname   = $_POST['iphorm_1_1'];
  8. $email      = $_POST['iphorm_1_2'];
  9. $phone      = $_POST['iphorm_1_8'];
  10. $city       = $_POST['iphorm_1_25'];
  11. $country    = $_POST['iphorm_1_4'];
  12. $qty        = $_POST['iphorm_1_5'];
  13. $product    = $_POST['iphorm_1_16'];
  14. $licenseown = $_POST['iphorm_1_6'];

  15. $count = count($product);

  16. if ($count > 0)
  17. {
  18.   $product = implode(" ", $product);
  19. }

  20.     // Zoho Api End Point
  21. $url = 'https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1';

  22. // Build Lead Data XML
  23. // Add or Remove Lead Fields. 
  24. $leadinfo = "<Leads>" .
  25. '<row no="1">' .
  26. '<FL val="Last Name">'.   $lastname   . "</FL>" .
  27. '<FL val="Company">'.     $company    . "</FL>" .
  28. '<FL val="Email">'.       $email      . "</FL>" .
  29. '<FL val="Phone">'.       $phone      . "</FL>" .
  30. '<FL val="City">'.        $city       . "</FL>" .
  31. '<FL val="Country">'.     $country    . "</FL>" .
  32. '<FL val="Qty">'.         $qty        . "</FL>" .
  33. '<FL val="Product">'.     $product    . "</FL>" .
  34. '<FL val="License own">'. $licenseown . "</FL>" .
  35. "</row>" .
  36. "</Leads>" ;

  37. // Prepare Curl Request Params
  38. $params = array(
  39.     'authtoken'    => "XXXXXXXXXXXXXXX",
  40.     'scope'        => "crmapi",
  41.     'xmlData'      => $leadinfo
  42.     );
  43.   
  44.     // Initialise CURL
  45.     $ch = curl_init();
  46.     curl_setopt($ch, CURLOPT_HEADER, 0);
  47.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  48.     curl_setopt($ch, CURLOPT_FAILONERROR, true);

  49.     // Post data
  50.     curl_setopt($ch, CURLOPT_POST, true);
  51.     curl_setopt($ch, CURLOPT_POSTFIELDS, $params);      
  52.     curl_setopt($ch, CURLOPT_URL, $url);

  53.     // Call
  54.     $output = curl_exec($ch);

  55.     // Analyse result
  56.     if ($output === false) {
  57.        $output = sprintf("CURL error (#%d) \"%s\". Requested URL was \"%s\".", curl_errno($ch), curl_error($ch), $url);
  58.     }
  59.     curl_close($ch);
  60. }
  61. add_action('iphorm_post_process_1', 'post_to_zoho', 10, 1);